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 = 35;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
222pub struct ProtocolVersion(u64);
223
224impl ProtocolVersion {
225 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
231
232 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
233
234 #[cfg(not(msim))]
235 const MAX_ALLOWED: Self = Self::MAX;
236
237 #[cfg(msim)]
240 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
241
242 pub fn new(v: u64) -> Self {
243 Self(v)
244 }
245
246 pub const fn as_u64(&self) -> u64 {
247 self.0
248 }
249
250 pub fn max() -> Self {
253 Self::MAX
254 }
255}
256
257impl From<u64> for ProtocolVersion {
258 fn from(v: u64) -> Self {
259 Self::new(v)
260 }
261}
262
263impl std::ops::Sub<u64> for ProtocolVersion {
264 type Output = Self;
265 fn sub(self, rhs: u64) -> Self::Output {
266 Self::new(self.0 - rhs)
267 }
268}
269
270impl std::ops::Add<u64> for ProtocolVersion {
271 type Output = Self;
272 fn add(self, rhs: u64) -> Self::Output {
273 Self::new(self.0 + rhs)
274 }
275}
276
277#[derive(
278 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
279)]
280pub enum Chain {
281 Mainnet,
282 Testnet,
283 #[default]
284 Unknown,
285}
286
287impl Chain {
288 pub fn as_str(self) -> &'static str {
289 match self {
290 Chain::Mainnet => "mainnet",
291 Chain::Testnet => "testnet",
292 Chain::Unknown => "unknown",
293 }
294 }
295}
296
297pub struct Error(pub String);
298
299#[derive(
303 Default,
304 Clone,
305 Serialize,
306 Deserialize,
307 Debug,
308 ProtocolConfigFeatureFlagsGetters,
309 ProtocolConfigOverride,
310)]
311struct FeatureFlags {
312 #[serde(skip_serializing_if = "is_true")]
318 disable_invariant_violation_check_in_swap_loc: bool,
319
320 #[serde(skip_serializing_if = "is_true")]
323 no_extraneous_module_bytes: bool,
324
325 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
327 consensus_transaction_ordering: ConsensusTransactionOrdering,
328
329 #[serde(skip_serializing_if = "is_true")]
332 hardened_otw_check: bool,
333
334 #[serde(skip_serializing_if = "is_false")]
336 enable_poseidon: bool,
337
338 #[serde(skip_serializing_if = "is_false")]
340 enable_group_ops_native_function_msm: bool,
341
342 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
344 per_object_congestion_control_mode: PerObjectCongestionControlMode,
345
346 #[serde(
348 default = "ConsensusChoice::mysticeti_deprecated",
349 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
350 )]
351 consensus_choice: ConsensusChoice,
352
353 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
355 consensus_network: ConsensusNetwork,
356
357 #[deprecated]
359 #[serde(skip_serializing_if = "Option::is_none")]
360 zklogin_max_epoch_upper_bound_delta: Option<u64>,
361
362 #[serde(skip_serializing_if = "is_false")]
364 enable_vdf: bool,
365
366 #[serde(skip_serializing_if = "is_false")]
368 passkey_auth: bool,
369
370 #[serde(skip_serializing_if = "is_true")]
373 rethrow_serialization_type_layout_errors: bool,
374
375 #[serde(skip_serializing_if = "is_false")]
377 relocate_event_module: bool,
378
379 #[serde(skip_serializing_if = "is_false")]
381 protocol_defined_base_fee: bool,
382
383 #[serde(skip_serializing_if = "is_false")]
385 uncompressed_g1_group_elements: bool,
386
387 #[serde(skip_serializing_if = "is_false")]
389 disallow_new_modules_in_deps_only_packages: bool,
390
391 #[serde(skip_serializing_if = "is_false")]
393 native_charging_v2: bool,
394
395 #[serde(skip_serializing_if = "is_false")]
397 convert_type_argument_error: bool,
398
399 #[serde(skip_serializing_if = "is_false")]
401 consensus_round_prober: bool,
402
403 #[serde(skip_serializing_if = "is_false")]
405 consensus_distributed_vote_scoring_strategy: bool,
406
407 #[serde(skip_serializing_if = "is_false")]
411 consensus_linearize_subdag_v2: bool,
412
413 #[serde(skip_serializing_if = "is_false")]
415 variant_nodes: bool,
416
417 #[serde(skip_serializing_if = "is_false")]
419 consensus_smart_ancestor_selection: bool,
420
421 #[serde(skip_serializing_if = "is_false")]
423 consensus_round_prober_probe_accepted_rounds: bool,
424
425 #[serde(skip_serializing_if = "is_false")]
427 consensus_zstd_compression: bool,
428
429 #[serde(skip_serializing_if = "is_false")]
432 congestion_control_min_free_execution_slot: bool,
433
434 #[serde(skip_serializing_if = "is_false")]
436 accept_passkey_in_multisig: bool,
437
438 #[serde(skip_serializing_if = "is_false")]
440 consensus_batched_block_sync: bool,
441
442 #[serde(skip_serializing_if = "is_false")]
445 congestion_control_gas_price_feedback_mechanism: bool,
446
447 #[serde(skip_serializing_if = "is_false")]
449 validate_identifier_inputs: bool,
450
451 #[serde(skip_serializing_if = "is_false")]
454 minimize_child_object_mutations: bool,
455
456 #[serde(skip_serializing_if = "is_false")]
458 dependency_linkage_error: bool,
459
460 #[serde(skip_serializing_if = "is_false")]
462 additional_multisig_checks: bool,
463
464 #[serde(skip_serializing_if = "is_false")]
467 normalize_ptb_arguments: bool,
468
469 #[serde(skip_serializing_if = "is_false")]
473 select_committee_from_eligible_validators: bool,
474
475 #[serde(skip_serializing_if = "is_false")]
482 track_non_committee_eligible_validators: bool,
483
484 #[serde(skip_serializing_if = "is_false")]
490 select_committee_supporting_next_epoch_version: bool,
491
492 #[serde(skip_serializing_if = "is_false")]
496 consensus_median_timestamp_with_checkpoint_enforcement: bool,
497
498 #[serde(skip_serializing_if = "is_false")]
500 consensus_commit_transactions_only_for_traversed_headers: bool,
501
502 #[serde(skip_serializing_if = "is_false")]
504 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
505
506 #[serde(skip_serializing_if = "is_false")]
509 separate_gas_price_feedback_mechanism_for_randomness: bool,
510
511 #[serde(skip_serializing_if = "is_false")]
514 metadata_in_module_bytes: bool,
515
516 #[serde(skip_serializing_if = "is_false")]
518 publish_package_metadata: bool,
519
520 #[serde(skip_serializing_if = "is_false")]
522 enable_move_authentication: bool,
523
524 #[serde(skip_serializing_if = "is_false")]
526 enable_move_authentication_for_sponsor: bool,
527
528 #[serde(skip_serializing_if = "is_false")]
530 pass_validator_scores_to_advance_epoch: bool,
531
532 #[serde(skip_serializing_if = "is_false")]
534 calculate_validator_scores: bool,
535
536 #[serde(skip_serializing_if = "is_false")]
538 adjust_rewards_by_score: bool,
539
540 #[serde(skip_serializing_if = "is_false")]
543 pass_calculated_validator_scores_to_advance_epoch: bool,
544
545 #[serde(skip_serializing_if = "is_false")]
550 consensus_fast_commit_sync: bool,
551
552 #[serde(skip_serializing_if = "is_false")]
555 consensus_block_restrictions: bool,
556
557 #[serde(skip_serializing_if = "is_false")]
559 move_native_tx_context: bool,
560
561 #[serde(skip_serializing_if = "is_false")]
563 additional_borrow_checks: bool,
564
565 #[serde(skip_serializing_if = "is_false")]
567 pre_consensus_sponsor_only_move_authentication: bool,
568
569 #[serde(skip_serializing_if = "is_false")]
571 consensus_starfish_speed: bool,
572
573 #[serde(skip_serializing_if = "is_false")]
580 always_advance_dkg_to_resolution: bool,
581
582 #[serde(skip_serializing_if = "is_false")]
587 enable_pcool_flow: bool,
588
589 #[serde(skip_serializing_if = "is_false")]
594 pcool_skip_immutable_object_locks: bool,
595
596 #[serde(skip_serializing_if = "is_false")]
598 validator_metadata_verify_v2: bool,
599
600 #[serde(skip_serializing_if = "is_false")]
604 deny_rule_governance: bool,
605
606 #[serde(skip_serializing_if = "is_false")]
611 deny_rule_governance_on_chain: bool,
612
613 #[serde(skip_serializing_if = "is_false")]
616 package_metadata_with_dynamic_module_metadata: bool,
617
618 #[serde(skip_serializing_if = "is_false")]
621 report_move_authentication_error: bool,
622
623 #[serde(skip_serializing_if = "is_false")]
628 consensus_enable_sliding_window_leader_schedule: bool,
629
630 #[serde(skip_serializing_if = "is_false")]
635 consensus_enable_absolute_score_leader_schedule: bool,
636
637 #[serde(skip_serializing_if = "is_false")]
639 max_ptb_value_size_v2: bool,
640
641 #[serde(skip_serializing_if = "is_false")]
643 allow_unbounded_system_objects: bool,
644}
645
646fn is_true(b: &bool) -> bool {
647 *b
648}
649
650fn is_false(b: &bool) -> bool {
651 !b
652}
653
654#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
656pub enum ConsensusTransactionOrdering {
657 #[default]
660 None,
661 ByGasPrice,
663}
664
665impl ConsensusTransactionOrdering {
666 pub fn is_none(&self) -> bool {
667 matches!(self, ConsensusTransactionOrdering::None)
668 }
669}
670
671#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
673pub enum PerObjectCongestionControlMode {
674 #[default]
675 None, TotalGasBudget, TotalTxCount, }
679
680impl PerObjectCongestionControlMode {
681 pub fn is_none(&self) -> bool {
682 matches!(self, PerObjectCongestionControlMode::None)
683 }
684}
685
686#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
688pub enum ConsensusChoice {
689 #[deprecated(note = "Mysticeti was replaced by Starfish")]
692 MysticetiDeprecated,
693 #[default]
694 Starfish,
695}
696
697#[expect(deprecated)]
698impl ConsensusChoice {
699 fn mysticeti_deprecated() -> Self {
706 ConsensusChoice::MysticetiDeprecated
707 }
708
709 pub fn is_mysticeti_deprecated(&self) -> bool {
710 matches!(self, ConsensusChoice::MysticetiDeprecated)
711 }
712 pub fn is_starfish(&self) -> bool {
713 matches!(self, ConsensusChoice::Starfish)
714 }
715}
716
717#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
719pub enum ConsensusNetwork {
720 #[default]
721 Tonic,
722}
723
724impl ConsensusNetwork {
725 pub fn is_tonic(&self) -> bool {
726 matches!(self, ConsensusNetwork::Tonic)
727 }
728}
729
730#[skip_serializing_none]
764#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
765pub struct ProtocolConfig {
766 pub version: ProtocolVersion,
767
768 feature_flags: FeatureFlags,
769
770 max_tx_size_bytes: Option<u64>,
775
776 max_input_objects: Option<u64>,
779
780 max_size_written_objects: Option<u64>,
785 max_size_written_objects_system_tx: Option<u64>,
789
790 max_serialized_tx_effects_size_bytes: Option<u64>,
792
793 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
795
796 max_gas_payment_objects: Option<u32>,
798
799 max_modules_in_publish: Option<u32>,
801
802 max_package_dependencies: Option<u32>,
804
805 max_arguments: Option<u32>,
808
809 max_type_arguments: Option<u32>,
811
812 max_type_argument_depth: Option<u32>,
814
815 max_pure_argument_size: Option<u32>,
817
818 max_programmable_tx_commands: Option<u32>,
820
821 move_binary_format_version: Option<u32>,
827 min_move_binary_format_version: Option<u32>,
828
829 binary_module_handles: Option<u16>,
831 binary_struct_handles: Option<u16>,
832 binary_function_handles: Option<u16>,
833 binary_function_instantiations: Option<u16>,
834 binary_signatures: Option<u16>,
835 binary_constant_pool: Option<u16>,
836 binary_identifiers: Option<u16>,
837 binary_address_identifiers: Option<u16>,
838 binary_struct_defs: Option<u16>,
839 binary_struct_def_instantiations: Option<u16>,
840 binary_function_defs: Option<u16>,
841 binary_field_handles: Option<u16>,
842 binary_field_instantiations: Option<u16>,
843 binary_friend_decls: Option<u16>,
844 binary_enum_defs: Option<u16>,
845 binary_enum_def_instantiations: Option<u16>,
846 binary_variant_handles: Option<u16>,
847 binary_variant_instantiation_handles: Option<u16>,
848
849 max_move_object_size: Option<u64>,
852
853 max_move_package_size: Option<u64>,
858
859 max_publish_or_upgrade_per_ptb: Option<u64>,
862
863 max_tx_gas: Option<u64>,
865
866 max_auth_gas: Option<u64>,
868
869 max_gas_price: Option<u64>,
872
873 max_gas_computation_bucket: Option<u64>,
876
877 gas_rounding_step: Option<u64>,
879
880 max_loop_depth: Option<u64>,
882
883 max_generic_instantiation_length: Option<u64>,
886
887 max_function_parameters: Option<u64>,
890
891 max_basic_blocks: Option<u64>,
894
895 max_value_stack_size: Option<u64>,
897
898 max_type_nodes: Option<u64>,
902
903 max_push_size: Option<u64>,
906
907 max_struct_definitions: Option<u64>,
910
911 max_function_definitions: Option<u64>,
914
915 max_fields_in_struct: Option<u64>,
918
919 max_dependency_depth: Option<u64>,
922
923 max_num_event_emit: Option<u64>,
926
927 max_num_new_move_object_ids: Option<u64>,
930
931 max_num_new_move_object_ids_system_tx: Option<u64>,
934
935 max_num_deleted_move_object_ids: Option<u64>,
938
939 max_num_deleted_move_object_ids_system_tx: Option<u64>,
942
943 max_num_transferred_move_object_ids: Option<u64>,
946
947 max_num_transferred_move_object_ids_system_tx: Option<u64>,
950
951 max_event_emit_size: Option<u64>,
953
954 max_event_emit_size_total: Option<u64>,
956
957 max_move_vector_len: Option<u64>,
960
961 max_move_identifier_len: Option<u64>,
964
965 max_move_value_depth: Option<u64>,
967
968 max_move_enum_variants: Option<u64>,
971
972 max_back_edges_per_function: Option<u64>,
975
976 max_back_edges_per_module: Option<u64>,
979
980 max_verifier_meter_ticks_per_function: Option<u64>,
983
984 max_meter_ticks_per_module: Option<u64>,
987
988 max_meter_ticks_per_package: Option<u64>,
991
992 object_runtime_max_num_cached_objects: Option<u64>,
999
1000 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
1003
1004 object_runtime_max_num_store_entries: Option<u64>,
1007
1008 object_runtime_max_num_store_entries_system_tx: Option<u64>,
1011
1012 base_tx_cost_fixed: Option<u64>,
1017
1018 package_publish_cost_fixed: Option<u64>,
1022
1023 base_tx_cost_per_byte: Option<u64>,
1027
1028 package_publish_cost_per_byte: Option<u64>,
1030
1031 obj_access_cost_read_per_byte: Option<u64>,
1033
1034 obj_access_cost_mutate_per_byte: Option<u64>,
1036
1037 obj_access_cost_delete_per_byte: Option<u64>,
1039
1040 obj_access_cost_verify_per_byte: Option<u64>,
1050
1051 max_type_to_layout_nodes: Option<u64>,
1053
1054 max_ptb_value_size: Option<u64>,
1056
1057 gas_model_version: Option<u64>,
1062
1063 obj_data_cost_refundable: Option<u64>,
1069
1070 obj_metadata_cost_non_refundable: Option<u64>,
1074
1075 storage_rebate_rate: Option<u64>,
1081
1082 reward_slashing_rate: Option<u64>,
1085
1086 storage_gas_price: Option<u64>,
1088
1089 base_gas_price: Option<u64>,
1091
1092 validator_target_reward: Option<u64>,
1094
1095 max_transactions_per_checkpoint: Option<u64>,
1102
1103 max_checkpoint_size_bytes: Option<u64>,
1107
1108 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1114
1115 address_from_bytes_cost_base: Option<u64>,
1120 address_to_u256_cost_base: Option<u64>,
1122 address_from_u256_cost_base: Option<u64>,
1124
1125 config_read_setting_impl_cost_base: Option<u64>,
1130 config_read_setting_impl_cost_per_byte: Option<u64>,
1131
1132 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1136 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1137 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1138 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1139 dynamic_field_add_child_object_cost_base: Option<u64>,
1142 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1143 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1144 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1145 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1148 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1149 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1150 dynamic_field_remove_child_object_cost_base: Option<u64>,
1153 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1154 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1155 dynamic_field_has_child_object_cost_base: Option<u64>,
1158 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1161 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1162 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1163
1164 event_emit_cost_base: Option<u64>,
1167 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1168 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1169 event_emit_output_cost_per_byte: Option<u64>,
1170
1171 object_borrow_uid_cost_base: Option<u64>,
1174 object_delete_impl_cost_base: Option<u64>,
1176 object_record_new_uid_cost_base: Option<u64>,
1178
1179 transfer_transfer_internal_cost_base: Option<u64>,
1182 transfer_freeze_object_cost_base: Option<u64>,
1184 transfer_share_object_cost_base: Option<u64>,
1186 transfer_receive_object_cost_base: Option<u64>,
1189
1190 tx_context_derive_id_cost_base: Option<u64>,
1193 tx_context_fresh_id_cost_base: Option<u64>,
1194 tx_context_sender_cost_base: Option<u64>,
1195 tx_context_digest_cost_base: Option<u64>,
1196 tx_context_epoch_cost_base: Option<u64>,
1197 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1198 tx_context_sponsor_cost_base: Option<u64>,
1199 tx_context_rgp_cost_base: Option<u64>,
1200 tx_context_gas_price_cost_base: Option<u64>,
1201 tx_context_gas_budget_cost_base: Option<u64>,
1202 tx_context_ids_created_cost_base: Option<u64>,
1203 tx_context_replace_cost_base: Option<u64>,
1204
1205 types_is_one_time_witness_cost_base: Option<u64>,
1208 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1209 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1210
1211 validator_validate_metadata_cost_base: Option<u64>,
1214 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1215
1216 crypto_invalid_arguments_cost: Option<u64>,
1218 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1220 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1221 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1222
1223 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1225 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1226 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1227
1228 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1230 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1231 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1232 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1233 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1234 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1235
1236 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1238
1239 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1241 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1242 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1243 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1244 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1245 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1246
1247 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1249 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1250 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1251 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1252 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1253 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1254
1255 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1257 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1258 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1259 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1260 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1261 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1262
1263 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1265 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1266 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1267
1268 ed25519_ed25519_verify_cost_base: Option<u64>,
1270 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1271 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1272
1273 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1275 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1276
1277 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1279 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1280 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1281 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1282 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1283
1284 hash_blake2b256_cost_base: Option<u64>,
1286 hash_blake2b256_data_cost_per_byte: Option<u64>,
1287 hash_blake2b256_data_cost_per_block: Option<u64>,
1288
1289 hash_keccak256_cost_base: Option<u64>,
1291 hash_keccak256_data_cost_per_byte: Option<u64>,
1292 hash_keccak256_data_cost_per_block: Option<u64>,
1293
1294 poseidon_bn254_cost_base: Option<u64>,
1296 poseidon_bn254_cost_per_block: Option<u64>,
1297
1298 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1300 group_ops_bls12381_decode_g1_cost: Option<u64>,
1301 group_ops_bls12381_decode_g2_cost: Option<u64>,
1302 group_ops_bls12381_decode_gt_cost: Option<u64>,
1303 group_ops_bls12381_scalar_add_cost: Option<u64>,
1304 group_ops_bls12381_g1_add_cost: Option<u64>,
1305 group_ops_bls12381_g2_add_cost: Option<u64>,
1306 group_ops_bls12381_gt_add_cost: Option<u64>,
1307 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1308 group_ops_bls12381_g1_sub_cost: Option<u64>,
1309 group_ops_bls12381_g2_sub_cost: Option<u64>,
1310 group_ops_bls12381_gt_sub_cost: Option<u64>,
1311 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1312 group_ops_bls12381_g1_mul_cost: Option<u64>,
1313 group_ops_bls12381_g2_mul_cost: Option<u64>,
1314 group_ops_bls12381_gt_mul_cost: Option<u64>,
1315 group_ops_bls12381_scalar_div_cost: Option<u64>,
1316 group_ops_bls12381_g1_div_cost: Option<u64>,
1317 group_ops_bls12381_g2_div_cost: Option<u64>,
1318 group_ops_bls12381_gt_div_cost: Option<u64>,
1319 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1320 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1321 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1322 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1323 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1324 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1325 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1326 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1327 group_ops_bls12381_msm_max_len: Option<u32>,
1328 group_ops_bls12381_pairing_cost: Option<u64>,
1329 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1330 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1331 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1332 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1333 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1334
1335 hmac_hmac_sha3_256_cost_base: Option<u64>,
1337 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1338 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1339
1340 #[deprecated]
1342 check_zklogin_id_cost_base: Option<u64>,
1343 #[deprecated]
1345 check_zklogin_issuer_cost_base: Option<u64>,
1346
1347 vdf_verify_vdf_cost: Option<u64>,
1348 vdf_hash_to_input_cost: Option<u64>,
1349
1350 bcs_per_byte_serialized_cost: Option<u64>,
1352 bcs_legacy_min_output_size_cost: Option<u64>,
1353 bcs_failure_cost: Option<u64>,
1354
1355 hash_sha2_256_base_cost: Option<u64>,
1356 hash_sha2_256_per_byte_cost: Option<u64>,
1357 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1358 hash_sha3_256_base_cost: Option<u64>,
1359 hash_sha3_256_per_byte_cost: Option<u64>,
1360 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1361 type_name_get_base_cost: Option<u64>,
1362 type_name_get_per_byte_cost: Option<u64>,
1363
1364 string_check_utf8_base_cost: Option<u64>,
1365 string_check_utf8_per_byte_cost: Option<u64>,
1366 string_is_char_boundary_base_cost: Option<u64>,
1367 string_sub_string_base_cost: Option<u64>,
1368 string_sub_string_per_byte_cost: Option<u64>,
1369 string_index_of_base_cost: Option<u64>,
1370 string_index_of_per_byte_pattern_cost: Option<u64>,
1371 string_index_of_per_byte_searched_cost: Option<u64>,
1372
1373 vector_empty_base_cost: Option<u64>,
1374 vector_length_base_cost: Option<u64>,
1375 vector_push_back_base_cost: Option<u64>,
1376 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1377 vector_borrow_base_cost: Option<u64>,
1378 vector_pop_back_base_cost: Option<u64>,
1379 vector_destroy_empty_base_cost: Option<u64>,
1380 vector_swap_base_cost: Option<u64>,
1381 debug_print_base_cost: Option<u64>,
1382 debug_print_stack_trace_base_cost: Option<u64>,
1383
1384 execution_version: Option<u64>,
1386
1387 consensus_bad_nodes_stake_threshold: Option<u64>,
1391
1392 #[deprecated]
1393 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1394 #[deprecated]
1398 max_age_of_jwk_in_epochs: Option<u64>,
1399
1400 random_beacon_reduction_allowed_delta: Option<u16>,
1404
1405 random_beacon_reduction_lower_bound: Option<u32>,
1408
1409 random_beacon_dkg_timeout_round: Option<u32>,
1412
1413 random_beacon_min_round_interval_ms: Option<u64>,
1415
1416 random_beacon_dkg_version: Option<u64>,
1420
1421 consensus_max_transaction_size_bytes: Option<u64>,
1426 consensus_max_transactions_in_block_bytes: Option<u64>,
1428 consensus_max_num_transactions_in_block: Option<u64>,
1430
1431 max_deferral_rounds_for_congestion_control: Option<u64>,
1435
1436 min_checkpoint_interval_ms: Option<u64>,
1438
1439 checkpoint_rate_window_size: Option<u64>,
1449
1450 checkpoint_summary_version_specific_data: Option<u64>,
1452
1453 max_soft_bundle_size: Option<u64>,
1456
1457 bridge_should_try_to_finalize_committee: Option<bool>,
1462
1463 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1469
1470 max_committee_members_count: Option<u64>,
1474
1475 deny_rule_update_max_entries_per_tx: Option<u64>,
1480
1481 deny_rule_removal_grace_round_floor: Option<u64>,
1486
1487 consensus_gc_depth: Option<u32>,
1490
1491 consensus_max_acknowledgments_per_block: Option<u32>,
1497
1498 max_congestion_limit_overshoot_per_commit: Option<u64>,
1503
1504 max_concurrent_execution_workers: Option<u16>,
1511
1512 scorer_version: Option<u16>,
1521
1522 auth_context_digest_cost_base: Option<u64>,
1525 auth_context_tx_data_bytes_cost_base: Option<u64>,
1527 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1528 auth_context_tx_commands_cost_base: Option<u64>,
1530 auth_context_tx_commands_cost_per_byte: Option<u64>,
1531 auth_context_tx_inputs_cost_base: Option<u64>,
1533 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1534 auth_context_replace_cost_base: Option<u64>,
1537 auth_context_replace_cost_per_byte: Option<u64>,
1538 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1542
1543 consensus_commits_per_schedule: Option<u32>,
1546
1547 min_validator_count: Option<u64>,
1550
1551 max_validator_count: Option<u64>,
1555
1556 min_validator_joining_stake: Option<u64>,
1560
1561 validator_low_stake_threshold: Option<u64>,
1566
1567 validator_very_low_stake_threshold: Option<u64>,
1571
1572 validator_low_stake_grace_period: Option<u64>,
1576
1577 consensus_leader_schedule_window_size: Option<u32>,
1581}
1582
1583impl ProtocolConfig {
1585 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1598 self.feature_flags
1599 .disable_invariant_violation_check_in_swap_loc
1600 }
1601
1602 pub fn no_extraneous_module_bytes(&self) -> bool {
1603 self.feature_flags.no_extraneous_module_bytes
1604 }
1605
1606 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1607 self.feature_flags.consensus_transaction_ordering
1608 }
1609
1610 pub fn dkg_version(&self) -> u64 {
1611 self.random_beacon_dkg_version.unwrap_or(1)
1613 }
1614
1615 pub fn hardened_otw_check(&self) -> bool {
1616 self.feature_flags.hardened_otw_check
1617 }
1618
1619 pub fn enable_poseidon(&self) -> bool {
1620 self.feature_flags.enable_poseidon
1621 }
1622
1623 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1624 self.feature_flags.enable_group_ops_native_function_msm
1625 }
1626
1627 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1628 self.feature_flags.per_object_congestion_control_mode
1629 }
1630
1631 pub fn consensus_choice(&self) -> ConsensusChoice {
1632 self.feature_flags.consensus_choice
1633 }
1634
1635 pub fn consensus_network(&self) -> ConsensusNetwork {
1636 self.feature_flags.consensus_network
1637 }
1638
1639 pub fn enable_vdf(&self) -> bool {
1640 self.feature_flags.enable_vdf
1641 }
1642
1643 pub fn passkey_auth(&self) -> bool {
1644 self.feature_flags.passkey_auth
1645 }
1646
1647 pub fn max_transaction_size_bytes(&self) -> u64 {
1648 self.consensus_max_transaction_size_bytes
1650 .unwrap_or(256 * 1024)
1651 }
1652
1653 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1654 if cfg!(msim) {
1655 256 * 1024
1656 } else {
1657 self.consensus_max_transactions_in_block_bytes
1658 .unwrap_or(512 * 1024)
1659 }
1660 }
1661
1662 pub fn max_num_transactions_in_block(&self) -> u64 {
1663 if cfg!(msim) {
1664 8
1665 } else {
1666 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1667 }
1668 }
1669
1670 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1671 self.feature_flags.rethrow_serialization_type_layout_errors
1672 }
1673
1674 pub fn relocate_event_module(&self) -> bool {
1675 self.feature_flags.relocate_event_module
1676 }
1677
1678 pub fn protocol_defined_base_fee(&self) -> bool {
1679 self.feature_flags.protocol_defined_base_fee
1680 }
1681
1682 pub fn uncompressed_g1_group_elements(&self) -> bool {
1683 self.feature_flags.uncompressed_g1_group_elements
1684 }
1685
1686 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1687 self.feature_flags
1688 .disallow_new_modules_in_deps_only_packages
1689 }
1690
1691 pub fn native_charging_v2(&self) -> bool {
1692 self.feature_flags.native_charging_v2
1693 }
1694
1695 pub fn consensus_round_prober(&self) -> bool {
1696 self.feature_flags.consensus_round_prober
1697 }
1698
1699 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1700 self.feature_flags
1701 .consensus_distributed_vote_scoring_strategy
1702 }
1703
1704 pub fn gc_depth(&self) -> u32 {
1705 if cfg!(msim) {
1706 min(5, self.consensus_gc_depth.unwrap_or(0))
1708 } else {
1709 self.consensus_gc_depth.unwrap_or(0)
1710 }
1711 }
1712
1713 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1714 let res = self.feature_flags.consensus_linearize_subdag_v2;
1715 assert!(
1716 !res || self.gc_depth() > 0,
1717 "The consensus linearize sub dag V2 requires GC to be enabled"
1718 );
1719 res
1720 }
1721
1722 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1723 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1724 }
1725
1726 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1727 2 * committee_size
1728 }
1729
1730 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1731 committee_size
1732 }
1733
1734 pub fn variant_nodes(&self) -> bool {
1735 self.feature_flags.variant_nodes
1736 }
1737
1738 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1739 self.feature_flags.consensus_smart_ancestor_selection
1740 }
1741
1742 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1743 self.feature_flags
1744 .consensus_round_prober_probe_accepted_rounds
1745 }
1746
1747 pub fn consensus_zstd_compression(&self) -> bool {
1748 self.feature_flags.consensus_zstd_compression
1749 }
1750
1751 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1752 self.feature_flags
1753 .congestion_control_min_free_execution_slot
1754 }
1755
1756 pub fn accept_passkey_in_multisig(&self) -> bool {
1757 self.feature_flags.accept_passkey_in_multisig
1758 }
1759
1760 pub fn consensus_batched_block_sync(&self) -> bool {
1761 self.feature_flags.consensus_batched_block_sync
1762 }
1763
1764 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1767 self.feature_flags
1768 .congestion_control_gas_price_feedback_mechanism
1769 }
1770
1771 pub fn validate_identifier_inputs(&self) -> bool {
1772 self.feature_flags.validate_identifier_inputs
1773 }
1774
1775 pub fn minimize_child_object_mutations(&self) -> bool {
1776 self.feature_flags.minimize_child_object_mutations
1777 }
1778
1779 pub fn dependency_linkage_error(&self) -> bool {
1780 self.feature_flags.dependency_linkage_error
1781 }
1782
1783 pub fn additional_multisig_checks(&self) -> bool {
1784 self.feature_flags.additional_multisig_checks
1785 }
1786
1787 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1788 0
1791 }
1792
1793 pub fn normalize_ptb_arguments(&self) -> bool {
1794 self.feature_flags.normalize_ptb_arguments
1795 }
1796
1797 pub fn select_committee_from_eligible_validators(&self) -> bool {
1798 let res = self.feature_flags.select_committee_from_eligible_validators;
1799 assert!(
1800 !res || (self.protocol_defined_base_fee()
1801 && self.max_committee_members_count_as_option().is_some()),
1802 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1803 );
1804 res
1805 }
1806
1807 pub fn track_non_committee_eligible_validators(&self) -> bool {
1808 self.feature_flags.track_non_committee_eligible_validators
1809 }
1810
1811 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1812 let res = self
1813 .feature_flags
1814 .select_committee_supporting_next_epoch_version;
1815 assert!(
1816 !res || (self.track_non_committee_eligible_validators()
1817 && self.select_committee_from_eligible_validators()),
1818 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1819 );
1820 res
1821 }
1822
1823 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1824 let res = self
1825 .feature_flags
1826 .consensus_median_timestamp_with_checkpoint_enforcement;
1827 assert!(
1828 !res || self.gc_depth() > 0,
1829 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1830 );
1831 res
1832 }
1833
1834 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1835 self.feature_flags
1836 .consensus_commit_transactions_only_for_traversed_headers
1837 }
1838
1839 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1842 self.feature_flags
1843 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1844 }
1845
1846 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1849 self.feature_flags
1850 .separate_gas_price_feedback_mechanism_for_randomness
1851 }
1852
1853 pub fn metadata_in_module_bytes(&self) -> bool {
1854 self.feature_flags.metadata_in_module_bytes
1855 }
1856
1857 pub fn publish_package_metadata(&self) -> bool {
1858 self.feature_flags.publish_package_metadata
1859 }
1860
1861 pub fn enable_move_authentication(&self) -> bool {
1862 self.feature_flags.enable_move_authentication
1863 }
1864
1865 pub fn additional_borrow_checks(&self) -> bool {
1866 self.feature_flags.additional_borrow_checks
1867 }
1868
1869 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1870 let enable_move_authentication_for_sponsor =
1871 self.feature_flags.enable_move_authentication_for_sponsor;
1872 assert!(
1873 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1874 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1875 );
1876 enable_move_authentication_for_sponsor
1877 }
1878
1879 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1880 self.feature_flags.pass_validator_scores_to_advance_epoch
1881 }
1882
1883 pub fn calculate_validator_scores(&self) -> bool {
1884 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1885 assert!(
1886 !calculate_validator_scores || self.scorer_version.is_some(),
1887 "calculate_validator_scores requires scorer_version to be set"
1888 );
1889 calculate_validator_scores
1890 }
1891
1892 pub fn adjust_rewards_by_score(&self) -> bool {
1893 let adjust = self.feature_flags.adjust_rewards_by_score;
1894 assert!(
1895 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1896 "adjust_rewards_by_score requires scorer_version to be set"
1897 );
1898 adjust
1899 }
1900
1901 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1902 let pass = self
1903 .feature_flags
1904 .pass_calculated_validator_scores_to_advance_epoch;
1905 assert!(
1906 !pass
1907 || (self.pass_validator_scores_to_advance_epoch()
1908 && self.calculate_validator_scores()),
1909 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1910 );
1911 pass
1912 }
1913 pub fn consensus_fast_commit_sync(&self) -> bool {
1914 let res = self.feature_flags.consensus_fast_commit_sync;
1915 assert!(
1916 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1917 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1918 );
1919 res
1920 }
1921
1922 pub fn consensus_block_restrictions(&self) -> bool {
1923 self.feature_flags.consensus_block_restrictions
1924 }
1925
1926 pub fn move_native_tx_context(&self) -> bool {
1927 self.feature_flags.move_native_tx_context
1928 }
1929
1930 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1931 let pre_consensus_sponsor_only_move_authentication = self
1932 .feature_flags
1933 .pre_consensus_sponsor_only_move_authentication;
1934 if pre_consensus_sponsor_only_move_authentication {
1935 assert!(
1936 self.enable_move_authentication(),
1937 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1938 );
1939 assert!(
1940 self.enable_move_authentication_for_sponsor(),
1941 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1942 );
1943 }
1944 pre_consensus_sponsor_only_move_authentication
1945 }
1946
1947 pub fn consensus_starfish_speed(&self) -> bool {
1948 let res = self.feature_flags.consensus_starfish_speed;
1949 assert!(
1950 !res || self.consensus_fast_commit_sync(),
1951 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1952 );
1953 res
1954 }
1955
1956 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1957 self.feature_flags.always_advance_dkg_to_resolution
1958 }
1959
1960 pub fn enable_pcool_flow(&self) -> bool {
1961 self.feature_flags.enable_pcool_flow
1962 }
1963
1964 pub fn pcool_skip_immutable_object_locks(&self) -> bool {
1965 self.feature_flags.pcool_skip_immutable_object_locks
1966 }
1967
1968 pub fn validator_metadata_verify_v2(&self) -> bool {
1969 self.feature_flags.validator_metadata_verify_v2
1970 }
1971
1972 pub fn commits_per_schedule(&self) -> u32 {
1973 let commits_per_schedule = if cfg!(msim) {
1974 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
1976 } else {
1977 self.consensus_commits_per_schedule.unwrap_or(300)
1978 };
1979 assert!(
1980 commits_per_schedule > 0,
1981 "consensus_commits_per_schedule must be greater than 0"
1982 );
1983 commits_per_schedule
1984 }
1985
1986 pub fn leader_schedule_window_size(&self) -> u32 {
1987 if cfg!(msim) {
1988 min(
1991 20,
1992 self.consensus_leader_schedule_window_size.unwrap_or(600),
1993 )
1994 } else {
1995 self.consensus_leader_schedule_window_size.unwrap_or(600)
1996 }
1997 }
1998
1999 pub fn consensus_enable_sliding_window_leader_schedule(&self) -> bool {
2000 let res = self
2001 .feature_flags
2002 .consensus_enable_sliding_window_leader_schedule;
2003 assert!(
2004 !res || self.leader_schedule_window_size() >= self.commits_per_schedule(),
2005 "consensus_enable_sliding_window_leader_schedule requires window_size >= commits_per_schedule"
2006 );
2007 res
2008 }
2009
2010 pub fn consensus_enable_absolute_score_leader_schedule(&self) -> bool {
2011 self.feature_flags
2012 .consensus_enable_absolute_score_leader_schedule
2013 }
2014
2015 pub fn max_ptb_value_size_v2(&self) -> bool {
2016 self.feature_flags.max_ptb_value_size_v2
2017 }
2018
2019 pub fn deny_rule_governance(&self) -> bool {
2020 self.feature_flags.deny_rule_governance
2021 }
2022
2023 pub fn deny_rule_governance_on_chain(&self) -> bool {
2024 self.feature_flags.deny_rule_governance_on_chain
2025 }
2026
2027 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
2028 let res = self
2029 .feature_flags
2030 .package_metadata_with_dynamic_module_metadata;
2031 assert!(
2032 !res || self.publish_package_metadata(),
2033 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
2034 );
2035 res
2036 }
2037
2038 pub fn report_move_authentication_error(&self) -> bool {
2039 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
2040 assert!(
2041 !report_move_authentication_error || self.enable_move_authentication(),
2042 "report_move_authentication_error requires enable_move_authentication to be set"
2043 );
2044 report_move_authentication_error
2045 }
2046
2047 pub fn concurrent_execution_workers(&self) -> Option<u16> {
2051 let res = self.max_concurrent_execution_workers;
2052 assert!(
2053 res.is_none() || self.enable_pcool_flow(),
2054 "max_concurrent_execution_workers requires enable_pcool_flow to be enabled"
2055 );
2056 assert!(
2057 res.is_none()
2058 || self
2059 .max_accumulated_txn_cost_per_object_in_mysticeti_commit
2060 .is_some(),
2061 "max_concurrent_execution_workers requires per-object congestion control \
2062 (max_accumulated_txn_cost_per_object_in_mysticeti_commit) to be enabled"
2063 );
2064 assert!(
2065 res.is_none() || self.congestion_control_gas_price_feedback_mechanism(),
2066 "max_concurrent_execution_workers requires the gas price feedback mechanism \
2067 (congestion_control_gas_price_feedback_mechanism), which carries the suggested \
2068 gas price of an execution-worker congestion cancellation"
2069 );
2070 assert!(
2071 res.is_none() || !self.separate_gas_price_feedback_mechanism_for_randomness(),
2072 "max_concurrent_execution_workers implies a single congestion tracker and suggested \
2073 gas price calculator for all transactions, which is incompatible with \
2074 separate_gas_price_feedback_mechanism_for_randomness"
2075 );
2076 assert!(
2077 res != Some(0),
2078 "max_concurrent_execution_workers must be positive when set"
2079 );
2080 res
2081 }
2082
2083 pub fn allow_unbounded_system_objects(&self) -> bool {
2084 self.feature_flags.allow_unbounded_system_objects
2085 }
2086}
2087
2088#[cfg(not(msim))]
2089static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2090
2091#[cfg(msim)]
2093thread_local! {
2094 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2095}
2096
2097impl ProtocolConfig {
2099 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2102 assert!(
2104 version >= ProtocolVersion::MIN,
2105 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2106 version,
2107 ProtocolVersion::MIN.0,
2108 );
2109 assert!(
2110 version <= ProtocolVersion::MAX_ALLOWED,
2111 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2112 version,
2113 ProtocolVersion::MAX_ALLOWED.0,
2114 );
2115
2116 let mut ret = Self::get_for_version_impl(version, chain);
2117 ret.version = version;
2118
2119 ret = CONFIG_OVERRIDE.with(|ovr| {
2120 if let Some(override_fn) = &*ovr.borrow() {
2121 warn!(
2122 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2123 );
2124 override_fn(version, ret)
2125 } else {
2126 ret
2127 }
2128 });
2129
2130 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2131 warn!(
2132 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2133 );
2134
2135 let overrides: ProtocolConfigOptional =
2137 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
2138 .expect("failed to parse ProtocolConfig override env variables");
2139 overrides.apply_to(&mut ret);
2140
2141 let feature_flag_overrides: FeatureFlagsOptional =
2143 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
2144 .expect("failed to parse ProtocolConfig feature flags override env variables");
2145
2146 feature_flag_overrides.apply_to(&mut ret.feature_flags);
2147 }
2148
2149 assert!(
2151 !ret.feature_flags.deny_rule_governance_on_chain
2152 || ret.feature_flags.deny_rule_governance,
2153 "deny_rule_governance_on_chain requires deny_rule_governance"
2154 );
2155 assert!(
2158 !ret.feature_flags.deny_rule_governance_on_chain
2159 || (ret.deny_rule_update_max_entries_per_tx.is_some()
2160 && ret.deny_rule_removal_grace_round_floor.is_some()),
2161 "deny_rule_governance_on_chain requires deny_rule_update_max_entries_per_tx and deny_rule_removal_grace_round_floor"
2162 );
2163 const DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING: u64 = 2048;
2171 assert!(
2172 ret.deny_rule_update_max_entries_per_tx
2173 .is_none_or(|max_entries| {
2174 max_entries > 0
2175 && max_entries <= DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING
2176 && [
2177 ret.max_num_new_move_object_ids_system_tx,
2178 ret.max_num_deleted_move_object_ids_system_tx,
2179 ret.object_runtime_max_num_cached_objects_system_tx,
2180 ret.object_runtime_max_num_store_entries_system_tx,
2181 ]
2182 .iter()
2183 .all(|limit| limit.is_none_or(|limit| max_entries <= limit))
2184 }),
2185 "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"
2186 );
2187
2188 ret
2189 }
2190
2191 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2194 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2195 let mut ret = Self::get_for_version_impl(version, chain);
2196 ret.version = version;
2197 Some(ret)
2198 } else {
2199 None
2200 }
2201 }
2202
2203 #[cfg(not(msim))]
2204 pub fn poison_get_for_min_version() {
2205 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2206 }
2207
2208 #[cfg(not(msim))]
2209 fn load_poison_get_for_min_version() -> bool {
2210 POISON_VERSION_METHODS.load(Ordering::Relaxed)
2211 }
2212
2213 #[cfg(msim)]
2214 pub fn poison_get_for_min_version() {
2215 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2216 }
2217
2218 #[cfg(msim)]
2219 fn load_poison_get_for_min_version() -> bool {
2220 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2221 }
2222
2223 pub fn convert_type_argument_error(&self) -> bool {
2224 self.feature_flags.convert_type_argument_error
2225 }
2226
2227 pub fn get_for_min_version() -> Self {
2231 if Self::load_poison_get_for_min_version() {
2232 panic!("get_for_min_version called on validator");
2233 }
2234 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2235 }
2236
2237 #[expect(non_snake_case)]
2248 pub fn get_for_max_version_UNSAFE() -> Self {
2249 if Self::load_poison_get_for_min_version() {
2250 panic!("get_for_max_version_UNSAFE called on validator");
2251 }
2252 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2253 }
2254
2255 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2256 #[cfg(msim)]
2257 {
2258 if version > ProtocolVersion::MAX {
2260 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2261 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2262 return config;
2263 }
2264 }
2265
2266 let mut cfg = Self {
2270 version,
2271
2272 feature_flags: Default::default(),
2273
2274 max_tx_size_bytes: Some(128 * 1024),
2275 max_input_objects: Some(2048),
2278 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2279 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2280 max_gas_payment_objects: Some(256),
2281 max_modules_in_publish: Some(64),
2282 max_package_dependencies: Some(32),
2283 max_arguments: Some(512),
2284 max_type_arguments: Some(16),
2285 max_type_argument_depth: Some(16),
2286 max_pure_argument_size: Some(16 * 1024),
2287 max_programmable_tx_commands: Some(1024),
2288 move_binary_format_version: Some(7),
2289 min_move_binary_format_version: Some(6),
2290 binary_module_handles: Some(100),
2291 binary_struct_handles: Some(300),
2292 binary_function_handles: Some(1500),
2293 binary_function_instantiations: Some(750),
2294 binary_signatures: Some(1000),
2295 binary_constant_pool: Some(4000),
2296 binary_identifiers: Some(10000),
2297 binary_address_identifiers: Some(100),
2298 binary_struct_defs: Some(200),
2299 binary_struct_def_instantiations: Some(100),
2300 binary_function_defs: Some(1000),
2301 binary_field_handles: Some(500),
2302 binary_field_instantiations: Some(250),
2303 binary_friend_decls: Some(100),
2304 binary_enum_defs: None,
2305 binary_enum_def_instantiations: None,
2306 binary_variant_handles: None,
2307 binary_variant_instantiation_handles: None,
2308 max_move_object_size: Some(250 * 1024),
2309 max_move_package_size: Some(100 * 1024),
2310 max_publish_or_upgrade_per_ptb: Some(5),
2311 max_auth_gas: None,
2313 max_tx_gas: Some(50_000_000_000),
2315 max_gas_price: Some(100_000),
2316 max_gas_computation_bucket: Some(5_000_000),
2317 max_loop_depth: Some(5),
2318 max_generic_instantiation_length: Some(32),
2319 max_function_parameters: Some(128),
2320 max_basic_blocks: Some(1024),
2321 max_value_stack_size: Some(1024),
2322 max_type_nodes: Some(256),
2323 max_push_size: Some(10000),
2324 max_struct_definitions: Some(200),
2325 max_function_definitions: Some(1000),
2326 max_fields_in_struct: Some(32),
2327 max_dependency_depth: Some(100),
2328 max_num_event_emit: Some(1024),
2329 max_num_new_move_object_ids: Some(2048),
2330 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2331 max_num_deleted_move_object_ids: Some(2048),
2332 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2333 max_num_transferred_move_object_ids: Some(2048),
2334 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2335 max_event_emit_size: Some(250 * 1024),
2336 max_move_vector_len: Some(256 * 1024),
2337 max_type_to_layout_nodes: None,
2338 max_ptb_value_size: None,
2339
2340 max_back_edges_per_function: Some(10_000),
2341 max_back_edges_per_module: Some(10_000),
2342
2343 max_verifier_meter_ticks_per_function: Some(16_000_000),
2344
2345 max_meter_ticks_per_module: Some(16_000_000),
2346 max_meter_ticks_per_package: Some(16_000_000),
2347
2348 object_runtime_max_num_cached_objects: Some(1000),
2349 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2350 object_runtime_max_num_store_entries: Some(1000),
2351 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2352 base_tx_cost_fixed: Some(1_000),
2354 package_publish_cost_fixed: Some(1_000),
2355 base_tx_cost_per_byte: Some(0),
2356 package_publish_cost_per_byte: Some(80),
2357 obj_access_cost_read_per_byte: Some(15),
2358 obj_access_cost_mutate_per_byte: Some(40),
2359 obj_access_cost_delete_per_byte: Some(40),
2360 obj_access_cost_verify_per_byte: Some(200),
2361 obj_data_cost_refundable: Some(100),
2362 obj_metadata_cost_non_refundable: Some(50),
2363 gas_model_version: Some(1),
2364 storage_rebate_rate: Some(10000),
2365 reward_slashing_rate: Some(10000),
2367 storage_gas_price: Some(76),
2368 base_gas_price: None,
2369 validator_target_reward: Some(767_000 * 1_000_000_000),
2372 max_transactions_per_checkpoint: Some(10_000),
2373 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2374
2375 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2377
2378 address_from_bytes_cost_base: Some(52),
2382 address_to_u256_cost_base: Some(52),
2384 address_from_u256_cost_base: Some(52),
2386
2387 config_read_setting_impl_cost_base: Some(100),
2390 config_read_setting_impl_cost_per_byte: Some(40),
2391
2392 dynamic_field_hash_type_and_key_cost_base: Some(100),
2396 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2397 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2398 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2399 dynamic_field_add_child_object_cost_base: Some(100),
2402 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2403 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2404 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2405 dynamic_field_borrow_child_object_cost_base: Some(100),
2408 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2409 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2410 dynamic_field_remove_child_object_cost_base: Some(100),
2413 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2414 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2415 dynamic_field_has_child_object_cost_base: Some(100),
2418 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2421 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2422 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2423
2424 event_emit_cost_base: Some(52),
2427 event_emit_value_size_derivation_cost_per_byte: Some(2),
2428 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2429 event_emit_output_cost_per_byte: Some(10),
2430
2431 object_borrow_uid_cost_base: Some(52),
2434 object_delete_impl_cost_base: Some(52),
2436 object_record_new_uid_cost_base: Some(52),
2438
2439 transfer_transfer_internal_cost_base: Some(52),
2443 transfer_freeze_object_cost_base: Some(52),
2445 transfer_share_object_cost_base: Some(52),
2447 transfer_receive_object_cost_base: Some(52),
2448
2449 tx_context_derive_id_cost_base: Some(52),
2453 tx_context_fresh_id_cost_base: None,
2454 tx_context_sender_cost_base: None,
2455 tx_context_digest_cost_base: None,
2456 tx_context_epoch_cost_base: None,
2457 tx_context_epoch_timestamp_ms_cost_base: None,
2458 tx_context_sponsor_cost_base: None,
2459 tx_context_rgp_cost_base: None,
2460 tx_context_gas_price_cost_base: None,
2461 tx_context_gas_budget_cost_base: None,
2462 tx_context_ids_created_cost_base: None,
2463 tx_context_replace_cost_base: None,
2464
2465 types_is_one_time_witness_cost_base: Some(52),
2468 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2469 types_is_one_time_witness_type_cost_per_byte: Some(2),
2470
2471 validator_validate_metadata_cost_base: Some(52),
2475 validator_validate_metadata_data_cost_per_byte: Some(2),
2476
2477 crypto_invalid_arguments_cost: Some(100),
2479 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2481 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2482 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2483
2484 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2486 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2487 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2488
2489 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2491 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2492 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2493 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2494 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2495 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2496
2497 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2499
2500 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2502 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2503 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2504 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2505 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2506 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2507
2508 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2510 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2511 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2512 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2513 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2514 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2515
2516 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2518 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2519 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2520 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2521 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2522 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2523
2524 ecvrf_ecvrf_verify_cost_base: Some(52),
2526 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2527 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2528
2529 ed25519_ed25519_verify_cost_base: Some(52),
2531 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2532 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2533
2534 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2536 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2537
2538 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2540 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2541 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2542 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2543 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2544
2545 hash_blake2b256_cost_base: Some(52),
2547 hash_blake2b256_data_cost_per_byte: Some(2),
2548 hash_blake2b256_data_cost_per_block: Some(2),
2549 hash_keccak256_cost_base: Some(52),
2551 hash_keccak256_data_cost_per_byte: Some(2),
2552 hash_keccak256_data_cost_per_block: Some(2),
2553
2554 poseidon_bn254_cost_base: None,
2555 poseidon_bn254_cost_per_block: None,
2556
2557 hmac_hmac_sha3_256_cost_base: Some(52),
2559 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2560 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2561
2562 group_ops_bls12381_decode_scalar_cost: Some(52),
2564 group_ops_bls12381_decode_g1_cost: Some(52),
2565 group_ops_bls12381_decode_g2_cost: Some(52),
2566 group_ops_bls12381_decode_gt_cost: Some(52),
2567 group_ops_bls12381_scalar_add_cost: Some(52),
2568 group_ops_bls12381_g1_add_cost: Some(52),
2569 group_ops_bls12381_g2_add_cost: Some(52),
2570 group_ops_bls12381_gt_add_cost: Some(52),
2571 group_ops_bls12381_scalar_sub_cost: Some(52),
2572 group_ops_bls12381_g1_sub_cost: Some(52),
2573 group_ops_bls12381_g2_sub_cost: Some(52),
2574 group_ops_bls12381_gt_sub_cost: Some(52),
2575 group_ops_bls12381_scalar_mul_cost: Some(52),
2576 group_ops_bls12381_g1_mul_cost: Some(52),
2577 group_ops_bls12381_g2_mul_cost: Some(52),
2578 group_ops_bls12381_gt_mul_cost: Some(52),
2579 group_ops_bls12381_scalar_div_cost: Some(52),
2580 group_ops_bls12381_g1_div_cost: Some(52),
2581 group_ops_bls12381_g2_div_cost: Some(52),
2582 group_ops_bls12381_gt_div_cost: Some(52),
2583 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2584 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2585 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2586 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2587 group_ops_bls12381_g1_msm_base_cost: Some(52),
2588 group_ops_bls12381_g2_msm_base_cost: Some(52),
2589 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2590 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2591 group_ops_bls12381_msm_max_len: Some(32),
2592 group_ops_bls12381_pairing_cost: Some(52),
2593 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2594 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2595 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2596 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2597 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2598
2599 #[allow(deprecated)]
2601 check_zklogin_id_cost_base: Some(200),
2602 #[allow(deprecated)]
2603 check_zklogin_issuer_cost_base: Some(200),
2605
2606 vdf_verify_vdf_cost: None,
2607 vdf_hash_to_input_cost: None,
2608
2609 bcs_per_byte_serialized_cost: Some(2),
2610 bcs_legacy_min_output_size_cost: Some(1),
2611 bcs_failure_cost: Some(52),
2612 hash_sha2_256_base_cost: Some(52),
2613 hash_sha2_256_per_byte_cost: Some(2),
2614 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2615 hash_sha3_256_base_cost: Some(52),
2616 hash_sha3_256_per_byte_cost: Some(2),
2617 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2618 type_name_get_base_cost: Some(52),
2619 type_name_get_per_byte_cost: Some(2),
2620 string_check_utf8_base_cost: Some(52),
2621 string_check_utf8_per_byte_cost: Some(2),
2622 string_is_char_boundary_base_cost: Some(52),
2623 string_sub_string_base_cost: Some(52),
2624 string_sub_string_per_byte_cost: Some(2),
2625 string_index_of_base_cost: Some(52),
2626 string_index_of_per_byte_pattern_cost: Some(2),
2627 string_index_of_per_byte_searched_cost: Some(2),
2628 vector_empty_base_cost: Some(52),
2629 vector_length_base_cost: Some(52),
2630 vector_push_back_base_cost: Some(52),
2631 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2632 vector_borrow_base_cost: Some(52),
2633 vector_pop_back_base_cost: Some(52),
2634 vector_destroy_empty_base_cost: Some(52),
2635 vector_swap_base_cost: Some(52),
2636 debug_print_base_cost: Some(52),
2637 debug_print_stack_trace_base_cost: Some(52),
2638
2639 max_size_written_objects: Some(5 * 1000 * 1000),
2640 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2643
2644 max_move_identifier_len: Some(128),
2646 max_move_value_depth: Some(128),
2647 max_move_enum_variants: None,
2648
2649 gas_rounding_step: Some(1_000),
2650
2651 execution_version: Some(1),
2652
2653 max_event_emit_size_total: Some(
2656 256 * 250 * 1024, ),
2658
2659 consensus_bad_nodes_stake_threshold: Some(20),
2666
2667 #[allow(deprecated)]
2669 max_jwk_votes_per_validator_per_epoch: Some(240),
2670
2671 #[allow(deprecated)]
2672 max_age_of_jwk_in_epochs: Some(1),
2673
2674 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2678
2679 random_beacon_reduction_allowed_delta: Some(800),
2680
2681 random_beacon_reduction_lower_bound: Some(1000),
2682 random_beacon_dkg_timeout_round: Some(3000),
2683 random_beacon_min_round_interval_ms: Some(500),
2684
2685 random_beacon_dkg_version: Some(1),
2686
2687 consensus_max_num_transactions_in_block: Some(512),
2691
2692 max_deferral_rounds_for_congestion_control: Some(10),
2693
2694 min_checkpoint_interval_ms: Some(200),
2695
2696 checkpoint_rate_window_size: None,
2697
2698 checkpoint_summary_version_specific_data: Some(1),
2699
2700 max_soft_bundle_size: Some(5),
2701
2702 bridge_should_try_to_finalize_committee: None,
2703
2704 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2705
2706 max_committee_members_count: None,
2707 deny_rule_update_max_entries_per_tx: None,
2708 deny_rule_removal_grace_round_floor: None,
2709
2710 consensus_gc_depth: None,
2711
2712 consensus_max_acknowledgments_per_block: None,
2713
2714 max_congestion_limit_overshoot_per_commit: None,
2715
2716 max_concurrent_execution_workers: None,
2717
2718 scorer_version: None,
2719
2720 auth_context_digest_cost_base: None,
2722 auth_context_tx_data_bytes_cost_base: None,
2723 auth_context_tx_data_bytes_cost_per_byte: None,
2724 auth_context_tx_commands_cost_base: None,
2725 auth_context_tx_commands_cost_per_byte: None,
2726 auth_context_tx_inputs_cost_base: None,
2727 auth_context_tx_inputs_cost_per_byte: None,
2728 auth_context_replace_cost_base: None,
2729 auth_context_replace_cost_per_byte: None,
2730 auth_context_authenticator_function_info_v1_cost_base: None,
2731 consensus_commits_per_schedule: None,
2732 min_validator_count: None,
2733 max_validator_count: None,
2734 min_validator_joining_stake: None,
2735 validator_low_stake_threshold: None,
2736 validator_very_low_stake_threshold: None,
2737 validator_low_stake_grace_period: None,
2738 consensus_leader_schedule_window_size: None,
2739 };
2742
2743 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2744
2745 {
2747 cfg.feature_flags
2748 .disable_invariant_violation_check_in_swap_loc = true;
2749 cfg.feature_flags.no_extraneous_module_bytes = true;
2750 cfg.feature_flags.hardened_otw_check = true;
2751 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2752 }
2753
2754 {
2756 #[allow(deprecated)]
2757 {
2758 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2759 }
2760 }
2761
2762 #[expect(deprecated)]
2766 {
2767 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2768 }
2769 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2771
2772 cfg.feature_flags.per_object_congestion_control_mode =
2773 PerObjectCongestionControlMode::TotalTxCount;
2774
2775 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2777
2778 if chain != Chain::Mainnet && chain != Chain::Testnet {
2780 cfg.feature_flags.enable_poseidon = true;
2781 cfg.poseidon_bn254_cost_base = Some(260);
2782 cfg.poseidon_bn254_cost_per_block = Some(10);
2783
2784 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2785
2786 cfg.feature_flags.enable_vdf = true;
2787 cfg.vdf_verify_vdf_cost = Some(1500);
2790 cfg.vdf_hash_to_input_cost = Some(100);
2791
2792 cfg.feature_flags.passkey_auth = true;
2793 }
2794
2795 for cur in 2..=version.0 {
2796 match cur {
2797 1 => unreachable!(),
2798 2 => {}
2800 3 => {
2801 cfg.feature_flags.relocate_event_module = true;
2802 }
2803 4 => {
2804 cfg.max_type_to_layout_nodes = Some(512);
2805 }
2806 5 => {
2807 cfg.feature_flags.protocol_defined_base_fee = true;
2808 cfg.base_gas_price = Some(1000);
2809
2810 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2811 cfg.feature_flags.convert_type_argument_error = true;
2812 cfg.feature_flags.native_charging_v2 = true;
2813
2814 if chain != Chain::Mainnet && chain != Chain::Testnet {
2815 cfg.feature_flags.uncompressed_g1_group_elements = true;
2816 }
2817
2818 cfg.gas_model_version = Some(2);
2819
2820 cfg.poseidon_bn254_cost_per_block = Some(388);
2821
2822 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2823 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2824 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2825 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2826 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2827 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2828 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2829 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2830
2831 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2833 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2834 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2835 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2836
2837 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2838 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2839 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2840 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2841 Some(8213);
2842 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2843 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2844 Some(9484);
2845
2846 cfg.hash_keccak256_cost_base = Some(10);
2847 cfg.hash_blake2b256_cost_base = Some(10);
2848
2849 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2851 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2852 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2853 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2854
2855 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2856 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2857 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2858 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2859
2860 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2861 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2862 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2863 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2864
2865 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2866 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2867 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2868 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2869
2870 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2871 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2872 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2873 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2874
2875 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2876 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2877
2878 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2879 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2880 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2881 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2882
2883 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2884 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2885 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2886 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2887 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2888
2889 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2890
2891 cfg.validator_validate_metadata_cost_base = Some(20000);
2892
2893 cfg.max_committee_members_count = Some(50);
2894 }
2895 6 => {
2896 cfg.max_ptb_value_size = Some(1024 * 1024);
2897 }
2898 7 => {
2899 }
2902 8 => {
2903 cfg.feature_flags.variant_nodes = true;
2904
2905 if chain != Chain::Mainnet {
2906 cfg.feature_flags.consensus_round_prober = true;
2908 cfg.feature_flags
2910 .consensus_distributed_vote_scoring_strategy = true;
2911 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2912 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2914 cfg.feature_flags
2916 .consensus_round_prober_probe_accepted_rounds = true;
2917 cfg.feature_flags.consensus_zstd_compression = true;
2919 cfg.consensus_gc_depth = Some(60);
2923 }
2924
2925 if chain != Chain::Testnet && chain != Chain::Mainnet {
2928 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2929 }
2930 }
2931 9 => {
2932 if chain != Chain::Mainnet {
2933 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2935 }
2936
2937 cfg.feature_flags.consensus_zstd_compression = true;
2939
2940 if chain != Chain::Testnet && chain != Chain::Mainnet {
2942 cfg.feature_flags.accept_passkey_in_multisig = true;
2943 }
2944
2945 cfg.bridge_should_try_to_finalize_committee = None;
2947 }
2948 10 => {
2949 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2952
2953 cfg.max_committee_members_count = Some(80);
2955
2956 cfg.feature_flags.consensus_round_prober = true;
2958 cfg.feature_flags
2960 .consensus_round_prober_probe_accepted_rounds = true;
2961 cfg.feature_flags
2963 .consensus_distributed_vote_scoring_strategy = true;
2964 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2966
2967 cfg.consensus_gc_depth = Some(60);
2972
2973 cfg.feature_flags.minimize_child_object_mutations = true;
2975
2976 if chain != Chain::Mainnet {
2977 cfg.feature_flags.consensus_batched_block_sync = true;
2979 }
2980
2981 if chain != Chain::Testnet && chain != Chain::Mainnet {
2982 cfg.feature_flags
2985 .congestion_control_gas_price_feedback_mechanism = true;
2986 }
2987
2988 cfg.feature_flags.validate_identifier_inputs = true;
2989 cfg.feature_flags.dependency_linkage_error = true;
2990 cfg.feature_flags.additional_multisig_checks = true;
2991 }
2992 11 => {
2993 }
2996 12 => {
2997 cfg.feature_flags
3000 .congestion_control_gas_price_feedback_mechanism = true;
3001
3002 cfg.feature_flags.normalize_ptb_arguments = true;
3004 }
3005 13 => {
3006 cfg.feature_flags.select_committee_from_eligible_validators = true;
3009 cfg.feature_flags.track_non_committee_eligible_validators = true;
3012
3013 if chain != Chain::Testnet && chain != Chain::Mainnet {
3014 cfg.feature_flags
3017 .select_committee_supporting_next_epoch_version = true;
3018 }
3019 }
3020 14 => {
3021 cfg.feature_flags.consensus_batched_block_sync = true;
3023
3024 if chain != Chain::Mainnet {
3025 cfg.feature_flags
3028 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3029 cfg.feature_flags
3033 .select_committee_supporting_next_epoch_version = true;
3034 }
3035 if chain != Chain::Testnet && chain != Chain::Mainnet {
3036 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3038 }
3039 }
3040 15 => {
3041 if chain != Chain::Mainnet && chain != Chain::Testnet {
3042 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3046 }
3047 }
3048 16 => {
3049 cfg.feature_flags
3052 .select_committee_supporting_next_epoch_version = true;
3053 cfg.feature_flags
3055 .consensus_commit_transactions_only_for_traversed_headers = true;
3056 }
3057 17 => {
3058 cfg.max_committee_members_count = Some(100);
3060 }
3061 18 => {
3062 if chain != Chain::Mainnet {
3063 cfg.feature_flags.passkey_auth = true;
3065 }
3066 }
3067 19 => {
3068 if chain != Chain::Testnet && chain != Chain::Mainnet {
3069 cfg.feature_flags
3072 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3073 cfg.feature_flags
3076 .separate_gas_price_feedback_mechanism_for_randomness = true;
3077 cfg.feature_flags.metadata_in_module_bytes = true;
3080 cfg.feature_flags.publish_package_metadata = true;
3081 cfg.feature_flags.enable_move_authentication = true;
3083 cfg.max_auth_gas = Some(250_000_000);
3085 cfg.transfer_receive_object_cost_base = Some(100);
3088 cfg.feature_flags.adjust_rewards_by_score = true;
3090 }
3091
3092 if chain != Chain::Mainnet {
3093 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3095
3096 cfg.feature_flags.calculate_validator_scores = true;
3098 cfg.scorer_version = Some(1);
3099 }
3100
3101 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
3103
3104 cfg.feature_flags.passkey_auth = true;
3106 }
3107 20 => {
3108 if chain != Chain::Testnet && chain != Chain::Mainnet {
3109 cfg.feature_flags
3111 .pass_calculated_validator_scores_to_advance_epoch = true;
3112 }
3113 }
3114 21 => {
3115 if chain != Chain::Testnet && chain != Chain::Mainnet {
3116 cfg.feature_flags.consensus_fast_commit_sync = true;
3118 }
3119 if chain != Chain::Mainnet {
3120 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3125 cfg.feature_flags
3128 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3129 cfg.feature_flags
3132 .separate_gas_price_feedback_mechanism_for_randomness = true;
3133 }
3134
3135 cfg.auth_context_digest_cost_base = Some(30);
3136 cfg.auth_context_tx_commands_cost_base = Some(30);
3137 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
3138 cfg.auth_context_tx_inputs_cost_base = Some(30);
3139 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
3140 cfg.auth_context_replace_cost_base = Some(30);
3141 cfg.auth_context_replace_cost_per_byte = Some(2);
3142
3143 if chain != Chain::Testnet && chain != Chain::Mainnet {
3144 cfg.max_auth_gas = Some(250_000);
3146 }
3147 }
3148 22 => {
3149 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3154 cfg.feature_flags
3157 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3158 cfg.feature_flags
3161 .separate_gas_price_feedback_mechanism_for_randomness = true;
3162
3163 if chain != Chain::Mainnet {
3164 cfg.feature_flags.metadata_in_module_bytes = true;
3167 cfg.feature_flags.publish_package_metadata = true;
3168 cfg.feature_flags.enable_move_authentication = true;
3170 cfg.max_auth_gas = Some(250_000);
3172 cfg.transfer_receive_object_cost_base = Some(100);
3175 }
3176
3177 if chain != Chain::Mainnet {
3178 cfg.feature_flags.consensus_fast_commit_sync = true;
3180 }
3181 }
3182 23 => {
3183 cfg.feature_flags.move_native_tx_context = true;
3185 cfg.tx_context_fresh_id_cost_base = Some(52);
3186 cfg.tx_context_sender_cost_base = Some(30);
3187 cfg.tx_context_digest_cost_base = Some(30);
3188 cfg.tx_context_epoch_cost_base = Some(30);
3189 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
3190 cfg.tx_context_sponsor_cost_base = Some(30);
3191 cfg.tx_context_rgp_cost_base = Some(30);
3192 cfg.tx_context_gas_price_cost_base = Some(30);
3193 cfg.tx_context_gas_budget_cost_base = Some(30);
3194 cfg.tx_context_ids_created_cost_base = Some(30);
3195 cfg.tx_context_replace_cost_base = Some(30);
3196 }
3197 24 => {
3198 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3200
3201 if chain != Chain::Testnet && chain != Chain::Mainnet {
3202 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3204 }
3205
3206 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
3209 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
3210
3211 cfg.feature_flags.additional_borrow_checks = true;
3213 }
3214 #[allow(deprecated)]
3215 25 => {
3216 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3219 cfg.check_zklogin_id_cost_base = None;
3220 cfg.check_zklogin_issuer_cost_base = None;
3221 cfg.max_jwk_votes_per_validator_per_epoch = None;
3222 cfg.max_age_of_jwk_in_epochs = None;
3223 }
3224 26 => {
3225 }
3228 27 => {
3229 if chain != Chain::Mainnet {
3230 cfg.feature_flags.consensus_block_restrictions = true;
3233 }
3234
3235 if chain != Chain::Testnet && chain != Chain::Mainnet {
3236 cfg.feature_flags
3238 .pre_consensus_sponsor_only_move_authentication = true;
3239 }
3240 }
3241 28 => {
3242 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3247
3248 cfg.feature_flags.metadata_in_module_bytes = true;
3251 cfg.feature_flags.publish_package_metadata = true;
3252 cfg.feature_flags.enable_move_authentication = true;
3254 cfg.transfer_receive_object_cost_base = Some(100);
3257
3258 if chain != Chain::Unknown {
3259 cfg.max_auth_gas = Some(20_000);
3261 }
3262
3263 if chain != Chain::Mainnet {
3264 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3266 cfg.feature_flags
3268 .pre_consensus_sponsor_only_move_authentication = true;
3269 }
3270 }
3271 29 => {
3272 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3278
3279 cfg.feature_flags
3282 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3283
3284 cfg.feature_flags.consensus_fast_commit_sync = true;
3286 cfg.feature_flags.consensus_block_restrictions = true;
3290 }
3291 30 => {
3292 }
3300 31 => {
3301 cfg.feature_flags.validator_metadata_verify_v2 = true;
3302
3303 if chain != Chain::Mainnet && chain != Chain::Testnet {
3304 cfg.checkpoint_rate_window_size = Some(20);
3307 cfg.feature_flags
3310 .package_metadata_with_dynamic_module_metadata = true;
3311 cfg.feature_flags.consensus_starfish_speed = true;
3314 }
3315
3316 cfg.feature_flags.report_move_authentication_error = true;
3317 }
3318 32 => {
3319 cfg.min_validator_count = Some(4);
3323 cfg.max_validator_count = Some(150);
3324 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3325 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3326 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3327 cfg.validator_low_stake_grace_period = Some(7);
3328
3329 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3331 cfg.feature_flags
3333 .pre_consensus_sponsor_only_move_authentication = true;
3334
3335 if chain != Chain::Mainnet {
3336 cfg.feature_flags.consensus_starfish_speed = true;
3339 cfg.checkpoint_rate_window_size = Some(20);
3342 cfg.feature_flags
3345 .package_metadata_with_dynamic_module_metadata = true;
3346 }
3347
3348 if chain != Chain::Mainnet && chain != Chain::Testnet {
3349 cfg.feature_flags
3353 .consensus_enable_sliding_window_leader_schedule = true;
3354 cfg.feature_flags
3355 .consensus_enable_absolute_score_leader_schedule = true;
3356 cfg.feature_flags.enable_pcool_flow = true;
3360 }
3361 }
3362 33 => {
3363 cfg.checkpoint_rate_window_size = Some(20);
3366 if chain != Chain::Mainnet {
3370 cfg.feature_flags
3371 .consensus_enable_sliding_window_leader_schedule = true;
3372 cfg.feature_flags
3373 .consensus_enable_absolute_score_leader_schedule = true;
3374 }
3375 }
3376 34 => {
3377 if chain != Chain::Testnet && chain != Chain::Mainnet {
3378 cfg.scorer_version = Some(2);
3382 }
3383 cfg.feature_flags.pcool_skip_immutable_object_locks = true;
3387
3388 if chain == Chain::Mainnet {
3389 cfg.feature_flags.enable_move_authentication_for_sponsor = false;
3391 cfg.feature_flags
3394 .pre_consensus_sponsor_only_move_authentication = false;
3395 }
3396 }
3397 35 => {
3398 cfg.feature_flags.max_ptb_value_size_v2 = true;
3400 cfg.feature_flags.allow_unbounded_system_objects = true;
3402 cfg.feature_flags.consensus_starfish_speed = true;
3405 }
3406 _ => panic!("unsupported version {version:?}"),
3417 }
3418 }
3419 cfg
3420 }
3421
3422 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3428 let (
3429 max_back_edges_per_function,
3430 max_back_edges_per_module,
3431 sanity_check_with_regex_reference_safety,
3432 ) = if let Some((
3433 max_back_edges_per_function,
3434 max_back_edges_per_module,
3435 sanity_check_with_regex_reference_safety,
3436 )) = signing_limits
3437 {
3438 (
3439 Some(max_back_edges_per_function),
3440 Some(max_back_edges_per_module),
3441 Some(sanity_check_with_regex_reference_safety),
3442 )
3443 } else {
3444 (None, None, None)
3445 };
3446
3447 let additional_borrow_checks = if signing_limits.is_some() {
3448 true
3451 } else {
3452 self.additional_borrow_checks()
3453 };
3454
3455 VerifierConfig {
3456 max_loop_depth: Some(self.max_loop_depth() as usize),
3457 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3458 max_function_parameters: Some(self.max_function_parameters() as usize),
3459 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3460 max_value_stack_size: self.max_value_stack_size() as usize,
3461 max_type_nodes: Some(self.max_type_nodes() as usize),
3462 max_push_size: Some(self.max_push_size() as usize),
3463 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3464 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3465 max_function_definitions: Some(self.max_function_definitions() as usize),
3466 max_data_definitions: Some(self.max_struct_definitions() as usize),
3467 max_constant_vector_len: Some(self.max_move_vector_len()),
3468 max_back_edges_per_function,
3469 max_back_edges_per_module,
3470 max_basic_blocks_in_script: None,
3471 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
3475 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3476 additional_borrow_checks,
3477 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3478 .map(|limit| limit as u128),
3479 }
3480 }
3481
3482 pub fn apply_overrides_for_testing(
3487 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3488 ) -> OverrideGuard {
3489 CONFIG_OVERRIDE.with(|ovr| {
3490 let mut cur = ovr.borrow_mut();
3491 assert!(cur.is_none(), "config override already present");
3492 *cur = Some(Box::new(override_fn));
3493 OverrideGuard
3494 })
3495 }
3496}
3497
3498impl ProtocolConfig {
3503 pub fn set_per_object_congestion_control_mode_for_testing(
3504 &mut self,
3505 val: PerObjectCongestionControlMode,
3506 ) {
3507 self.feature_flags.per_object_congestion_control_mode = val;
3508 }
3509
3510 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3511 self.feature_flags.consensus_choice = val;
3512 }
3513
3514 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3515 self.feature_flags.consensus_network = val;
3516 }
3517
3518 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3519 self.feature_flags.passkey_auth = val
3520 }
3521
3522 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3523 self.feature_flags
3524 .disallow_new_modules_in_deps_only_packages = val;
3525 }
3526
3527 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3528 self.feature_flags.consensus_round_prober = val;
3529 }
3530
3531 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3532 self.feature_flags
3533 .consensus_distributed_vote_scoring_strategy = val;
3534 }
3535
3536 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3537 self.consensus_gc_depth = Some(val);
3538 }
3539
3540 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3541 self.feature_flags.consensus_linearize_subdag_v2 = val;
3542 }
3543
3544 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3545 self.feature_flags
3546 .consensus_round_prober_probe_accepted_rounds = val;
3547 }
3548
3549 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3550 self.feature_flags.accept_passkey_in_multisig = val;
3551 }
3552
3553 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3554 self.feature_flags.consensus_smart_ancestor_selection = val;
3555 }
3556
3557 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3558 self.feature_flags.consensus_batched_block_sync = val;
3559 }
3560
3561 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3562 self.feature_flags
3563 .congestion_control_min_free_execution_slot = val;
3564 }
3565
3566 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3567 self.feature_flags
3568 .congestion_control_gas_price_feedback_mechanism = val;
3569 }
3570
3571 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3572 self.feature_flags.select_committee_from_eligible_validators = val;
3573 }
3574
3575 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3576 self.feature_flags.track_non_committee_eligible_validators = val;
3577 }
3578
3579 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3580 self.feature_flags
3581 .select_committee_supporting_next_epoch_version = val;
3582 }
3583
3584 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3585 &mut self,
3586 val: bool,
3587 ) {
3588 self.feature_flags
3589 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3590 }
3591
3592 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3593 &mut self,
3594 val: bool,
3595 ) {
3596 self.feature_flags
3597 .consensus_commit_transactions_only_for_traversed_headers = val;
3598 }
3599
3600 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3601 &mut self,
3602 val: bool,
3603 ) {
3604 self.feature_flags
3605 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3606 }
3607
3608 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3609 &mut self,
3610 val: bool,
3611 ) {
3612 self.feature_flags
3613 .separate_gas_price_feedback_mechanism_for_randomness = val;
3614 }
3615
3616 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3617 self.feature_flags.metadata_in_module_bytes = val;
3618 }
3619
3620 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3621 self.feature_flags.publish_package_metadata = val;
3622 }
3623
3624 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3625 self.feature_flags.enable_move_authentication = val;
3626 }
3627
3628 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3629 self.feature_flags.enable_move_authentication_for_sponsor = val;
3630 }
3631
3632 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3633 self.feature_flags.consensus_fast_commit_sync = val;
3634 }
3635
3636 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3637 self.feature_flags.consensus_block_restrictions = val;
3638 }
3639
3640 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3641 self.feature_flags
3642 .pre_consensus_sponsor_only_move_authentication = val;
3643 }
3644
3645 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3646 self.feature_flags.consensus_starfish_speed = val;
3647 }
3648
3649 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3650 self.feature_flags.always_advance_dkg_to_resolution = val;
3651 }
3652
3653 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3654 self.feature_flags.enable_pcool_flow = val;
3655 }
3656
3657 pub fn set_pcool_skip_immutable_object_locks_for_testing(&mut self, val: bool) {
3658 self.feature_flags.pcool_skip_immutable_object_locks = val;
3659 }
3660
3661 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3662 self.consensus_commits_per_schedule = Some(val);
3663 }
3664
3665 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3666 self.feature_flags.deny_rule_governance = val;
3667 }
3668
3669 pub fn set_deny_rule_governance_on_chain_for_testing(&mut self, val: bool) {
3670 self.feature_flags.deny_rule_governance_on_chain = val;
3671 }
3672
3673 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
3674 self.feature_flags
3675 .package_metadata_with_dynamic_module_metadata = val;
3676 }
3677
3678 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
3679 self.feature_flags.report_move_authentication_error = val;
3680 }
3681
3682 pub fn set_leader_schedule_window_size_for_testing(&mut self, val: u32) {
3683 self.consensus_leader_schedule_window_size = Some(val);
3684 }
3685
3686 pub fn set_consensus_enable_sliding_window_leader_schedule_for_testing(&mut self, val: bool) {
3687 self.feature_flags
3688 .consensus_enable_sliding_window_leader_schedule = val;
3689 }
3690
3691 pub fn set_consensus_enable_absolute_score_leader_schedule_for_testing(&mut self, val: bool) {
3692 self.feature_flags
3693 .consensus_enable_absolute_score_leader_schedule = val;
3694 }
3695}
3696
3697type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3698
3699thread_local! {
3700 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3701}
3702
3703#[must_use]
3704pub struct OverrideGuard;
3705
3706impl Drop for OverrideGuard {
3707 fn drop(&mut self) {
3708 info!("restoring override fn");
3709 CONFIG_OVERRIDE.with(|ovr| {
3710 *ovr.borrow_mut() = None;
3711 });
3712 }
3713}
3714
3715#[derive(PartialEq, Eq)]
3719pub enum LimitThresholdCrossed {
3720 None,
3721 Soft(u128, u128),
3722 Hard(u128, u128),
3723}
3724
3725pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3728 x: T,
3729 soft_limit: U,
3730 hard_limit: V,
3731) -> LimitThresholdCrossed {
3732 let x: V = x.into();
3733 let soft_limit: V = soft_limit.into();
3734
3735 debug_assert!(soft_limit <= hard_limit);
3736
3737 if x >= hard_limit {
3740 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3741 } else if x < soft_limit {
3742 LimitThresholdCrossed::None
3743 } else {
3744 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3745 }
3746}
3747
3748#[macro_export]
3749macro_rules! check_limit {
3750 ($x:expr, $hard:expr) => {
3751 check_limit!($x, $hard, $hard)
3752 };
3753 ($x:expr, $soft:expr, $hard:expr) => {
3754 check_limit_in_range($x as u64, $soft, $hard)
3755 };
3756}
3757
3758#[macro_export]
3762macro_rules! check_limit_by_meter {
3763 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3764 let (h, metered_str) = if $is_metered {
3766 ($metered_limit, "metered")
3767 } else {
3768 ($unmetered_hard_limit, "unmetered")
3770 };
3771 use iota_protocol_config::check_limit_in_range;
3772 let result = check_limit_in_range($x as u64, $metered_limit, h);
3773 match result {
3774 LimitThresholdCrossed::None => {}
3775 LimitThresholdCrossed::Soft(_, _) => {
3776 $metric.with_label_values(&[metered_str, "soft"]).inc();
3777 }
3778 LimitThresholdCrossed::Hard(_, _) => {
3779 $metric.with_label_values(&[metered_str, "hard"]).inc();
3780 }
3781 };
3782 result
3783 }};
3784}
3785
3786#[cfg(all(test, not(msim)))]
3787mod test {
3788 use insta::assert_yaml_snapshot;
3789
3790 use super::*;
3791
3792 #[test]
3793 fn snapshot_tests() {
3794 println!("\n============================================================================");
3795 println!("! !");
3796 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3797 println!("! !");
3798 println!("============================================================================\n");
3799 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3800 let chain_str = match chain_id {
3805 Chain::Unknown => "".to_string(),
3806 _ => format!("{chain_id:?}_"),
3807 };
3808 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3809 let cur = ProtocolVersion::new(i);
3810 assert_yaml_snapshot!(
3811 format!("{}version_{}", chain_str, cur.as_u64()),
3812 ProtocolConfig::get_for_version(cur, *chain_id)
3813 );
3814 }
3815 }
3816 }
3817
3818 #[test]
3819 fn test_getters() {
3820 let prot: ProtocolConfig =
3821 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3822 assert_eq!(
3823 prot.max_arguments(),
3824 prot.max_arguments_as_option().unwrap()
3825 );
3826 }
3827
3828 #[test]
3829 fn test_setters() {
3830 let mut prot: ProtocolConfig =
3831 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3832 prot.set_max_arguments_for_testing(123);
3833 assert_eq!(prot.max_arguments(), 123);
3834
3835 prot.set_max_arguments_from_str_for_testing("321".to_string());
3836 assert_eq!(prot.max_arguments(), 321);
3837
3838 prot.disable_max_arguments_for_testing();
3839 assert_eq!(prot.max_arguments_as_option(), None);
3840
3841 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3842 assert_eq!(prot.max_arguments(), 456);
3843 }
3844
3845 #[test]
3846 #[should_panic(expected = "unsupported version")]
3847 fn max_version_test() {
3848 let _ = ProtocolConfig::get_for_version_impl(
3851 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3852 Chain::Unknown,
3853 );
3854 }
3855
3856 #[test]
3857 fn lookup_by_string_test() {
3858 let prot: ProtocolConfig =
3859 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3860 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3862
3863 assert!(
3864 prot.lookup_attr("max_arguments".to_string())
3865 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3866 );
3867
3868 assert!(
3870 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3871 .is_none()
3872 );
3873 assert!(
3874 prot.attr_map()
3875 .get("poseidon_bn254_cost_base")
3876 .unwrap()
3877 .is_none()
3878 );
3879
3880 let prot: ProtocolConfig =
3882 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3883
3884 assert!(
3885 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3886 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3887 );
3888 assert!(
3889 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3890 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3891 );
3892
3893 let prot: ProtocolConfig =
3895 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3896 assert!(
3898 prot.feature_flags
3899 .lookup_attr("some random string".to_owned())
3900 .is_none()
3901 );
3902 assert!(
3903 !prot
3904 .feature_flags
3905 .attr_map()
3906 .contains_key("some random string")
3907 );
3908
3909 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3911 assert!(
3912 prot.feature_flags
3913 .attr_map()
3914 .get("enable_poseidon")
3915 .unwrap()
3916 == &false
3917 );
3918 let prot: ProtocolConfig =
3919 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3920 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3922 assert!(
3923 prot.feature_flags
3924 .attr_map()
3925 .get("enable_poseidon")
3926 .unwrap()
3927 == &true
3928 );
3929 }
3930
3931 #[test]
3935 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
3936 fn deny_rule_chunk_limit_above_the_ceiling_is_rejected() {
3937 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
3938 config.set_deny_rule_governance_for_testing(true);
3939 config.set_deny_rule_governance_on_chain_for_testing(true);
3940 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
3941 config.set_deny_rule_update_max_entries_per_tx_for_testing(2048 + 1);
3942 config
3943 });
3944 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
3945 }
3946
3947 #[test]
3950 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
3951 fn deny_rule_chunk_limit_of_zero_is_rejected() {
3952 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
3953 config.set_deny_rule_governance_for_testing(true);
3954 config.set_deny_rule_governance_on_chain_for_testing(true);
3955 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
3956 config.set_deny_rule_update_max_entries_per_tx_for_testing(0);
3957 config
3958 });
3959 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
3960 }
3961
3962 #[test]
3964 fn deny_rule_chunk_limit_within_system_tx_object_id_limit_is_accepted() {
3965 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
3966 config.set_deny_rule_governance_for_testing(true);
3967 config.set_deny_rule_governance_on_chain_for_testing(true);
3968 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
3969 config.set_deny_rule_update_max_entries_per_tx_for_testing(1000);
3970 config
3971 });
3972 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
3973 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
3974 }
3975
3976 #[test]
3977 fn limit_range_fn_test() {
3978 let low = 100u32;
3979 let high = 10000u64;
3980
3981 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3982 assert!(matches!(
3983 check_limit!(255u16, low, high),
3984 LimitThresholdCrossed::Soft(255u128, 100)
3985 ));
3986 assert!(matches!(
3993 check_limit!(2550000u64, low, high),
3994 LimitThresholdCrossed::Hard(2550000, 10000)
3995 ));
3996
3997 assert!(matches!(
3998 check_limit!(2550000u64, high, high),
3999 LimitThresholdCrossed::Hard(2550000, 10000)
4000 ));
4001
4002 assert!(matches!(
4003 check_limit!(1u8, high),
4004 LimitThresholdCrossed::None
4005 ));
4006
4007 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
4008
4009 assert!(matches!(
4010 check_limit!(2550000u64, high),
4011 LimitThresholdCrossed::Hard(2550000, 10000)
4012 ));
4013 }
4014}