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 = 33;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
208pub struct ProtocolVersion(u64);
209
210impl ProtocolVersion {
211 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
217
218 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
219
220 #[cfg(not(msim))]
221 const MAX_ALLOWED: Self = Self::MAX;
222
223 #[cfg(msim)]
226 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
227
228 pub fn new(v: u64) -> Self {
229 Self(v)
230 }
231
232 pub const fn as_u64(&self) -> u64 {
233 self.0
234 }
235
236 pub fn max() -> Self {
239 Self::MAX
240 }
241}
242
243impl From<u64> for ProtocolVersion {
244 fn from(v: u64) -> Self {
245 Self::new(v)
246 }
247}
248
249impl std::ops::Sub<u64> for ProtocolVersion {
250 type Output = Self;
251 fn sub(self, rhs: u64) -> Self::Output {
252 Self::new(self.0 - rhs)
253 }
254}
255
256impl std::ops::Add<u64> for ProtocolVersion {
257 type Output = Self;
258 fn add(self, rhs: u64) -> Self::Output {
259 Self::new(self.0 + rhs)
260 }
261}
262
263#[derive(
264 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
265)]
266pub enum Chain {
267 Mainnet,
268 Testnet,
269 #[default]
270 Unknown,
271}
272
273impl Chain {
274 pub fn as_str(self) -> &'static str {
275 match self {
276 Chain::Mainnet => "mainnet",
277 Chain::Testnet => "testnet",
278 Chain::Unknown => "unknown",
279 }
280 }
281}
282
283pub struct Error(pub String);
284
285#[derive(
289 Default,
290 Clone,
291 Serialize,
292 Deserialize,
293 Debug,
294 ProtocolConfigFeatureFlagsGetters,
295 ProtocolConfigOverride,
296)]
297struct FeatureFlags {
298 #[serde(skip_serializing_if = "is_true")]
304 disable_invariant_violation_check_in_swap_loc: bool,
305
306 #[serde(skip_serializing_if = "is_true")]
309 no_extraneous_module_bytes: bool,
310
311 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
313 consensus_transaction_ordering: ConsensusTransactionOrdering,
314
315 #[serde(skip_serializing_if = "is_true")]
318 hardened_otw_check: bool,
319
320 #[serde(skip_serializing_if = "is_false")]
322 enable_poseidon: bool,
323
324 #[serde(skip_serializing_if = "is_false")]
326 enable_group_ops_native_function_msm: bool,
327
328 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
330 per_object_congestion_control_mode: PerObjectCongestionControlMode,
331
332 #[serde(
334 default = "ConsensusChoice::mysticeti_deprecated",
335 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
336 )]
337 consensus_choice: ConsensusChoice,
338
339 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
341 consensus_network: ConsensusNetwork,
342
343 #[deprecated]
345 #[serde(skip_serializing_if = "Option::is_none")]
346 zklogin_max_epoch_upper_bound_delta: Option<u64>,
347
348 #[serde(skip_serializing_if = "is_false")]
350 enable_vdf: bool,
351
352 #[serde(skip_serializing_if = "is_false")]
354 passkey_auth: bool,
355
356 #[serde(skip_serializing_if = "is_true")]
359 rethrow_serialization_type_layout_errors: bool,
360
361 #[serde(skip_serializing_if = "is_false")]
363 relocate_event_module: bool,
364
365 #[serde(skip_serializing_if = "is_false")]
367 protocol_defined_base_fee: bool,
368
369 #[serde(skip_serializing_if = "is_false")]
371 uncompressed_g1_group_elements: bool,
372
373 #[serde(skip_serializing_if = "is_false")]
375 disallow_new_modules_in_deps_only_packages: bool,
376
377 #[serde(skip_serializing_if = "is_false")]
379 native_charging_v2: bool,
380
381 #[serde(skip_serializing_if = "is_false")]
383 convert_type_argument_error: bool,
384
385 #[serde(skip_serializing_if = "is_false")]
387 consensus_round_prober: bool,
388
389 #[serde(skip_serializing_if = "is_false")]
391 consensus_distributed_vote_scoring_strategy: bool,
392
393 #[serde(skip_serializing_if = "is_false")]
397 consensus_linearize_subdag_v2: bool,
398
399 #[serde(skip_serializing_if = "is_false")]
401 variant_nodes: bool,
402
403 #[serde(skip_serializing_if = "is_false")]
405 consensus_smart_ancestor_selection: bool,
406
407 #[serde(skip_serializing_if = "is_false")]
409 consensus_round_prober_probe_accepted_rounds: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
413 consensus_zstd_compression: bool,
414
415 #[serde(skip_serializing_if = "is_false")]
418 congestion_control_min_free_execution_slot: bool,
419
420 #[serde(skip_serializing_if = "is_false")]
422 accept_passkey_in_multisig: bool,
423
424 #[serde(skip_serializing_if = "is_false")]
426 consensus_batched_block_sync: bool,
427
428 #[serde(skip_serializing_if = "is_false")]
431 congestion_control_gas_price_feedback_mechanism: bool,
432
433 #[serde(skip_serializing_if = "is_false")]
435 validate_identifier_inputs: bool,
436
437 #[serde(skip_serializing_if = "is_false")]
440 minimize_child_object_mutations: bool,
441
442 #[serde(skip_serializing_if = "is_false")]
444 dependency_linkage_error: bool,
445
446 #[serde(skip_serializing_if = "is_false")]
448 additional_multisig_checks: bool,
449
450 #[serde(skip_serializing_if = "is_false")]
453 normalize_ptb_arguments: bool,
454
455 #[serde(skip_serializing_if = "is_false")]
459 select_committee_from_eligible_validators: bool,
460
461 #[serde(skip_serializing_if = "is_false")]
468 track_non_committee_eligible_validators: bool,
469
470 #[serde(skip_serializing_if = "is_false")]
476 select_committee_supporting_next_epoch_version: bool,
477
478 #[serde(skip_serializing_if = "is_false")]
482 consensus_median_timestamp_with_checkpoint_enforcement: bool,
483
484 #[serde(skip_serializing_if = "is_false")]
486 consensus_commit_transactions_only_for_traversed_headers: bool,
487
488 #[serde(skip_serializing_if = "is_false")]
490 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
491
492 #[serde(skip_serializing_if = "is_false")]
495 separate_gas_price_feedback_mechanism_for_randomness: bool,
496
497 #[serde(skip_serializing_if = "is_false")]
500 metadata_in_module_bytes: bool,
501
502 #[serde(skip_serializing_if = "is_false")]
504 publish_package_metadata: bool,
505
506 #[serde(skip_serializing_if = "is_false")]
508 enable_move_authentication: bool,
509
510 #[serde(skip_serializing_if = "is_false")]
512 enable_move_authentication_for_sponsor: bool,
513
514 #[serde(skip_serializing_if = "is_false")]
516 pass_validator_scores_to_advance_epoch: bool,
517
518 #[serde(skip_serializing_if = "is_false")]
520 calculate_validator_scores: bool,
521
522 #[serde(skip_serializing_if = "is_false")]
524 adjust_rewards_by_score: bool,
525
526 #[serde(skip_serializing_if = "is_false")]
529 pass_calculated_validator_scores_to_advance_epoch: bool,
530
531 #[serde(skip_serializing_if = "is_false")]
536 consensus_fast_commit_sync: bool,
537
538 #[serde(skip_serializing_if = "is_false")]
541 consensus_block_restrictions: bool,
542
543 #[serde(skip_serializing_if = "is_false")]
545 move_native_tx_context: bool,
546
547 #[serde(skip_serializing_if = "is_false")]
549 additional_borrow_checks: bool,
550
551 #[serde(skip_serializing_if = "is_false")]
553 pre_consensus_sponsor_only_move_authentication: bool,
554
555 #[serde(skip_serializing_if = "is_false")]
557 consensus_starfish_speed: bool,
558
559 #[serde(skip_serializing_if = "is_false")]
566 always_advance_dkg_to_resolution: bool,
567
568 #[serde(skip_serializing_if = "is_false")]
573 enable_pcool_flow: bool,
574
575 #[serde(skip_serializing_if = "is_false")]
577 validator_metadata_verify_v2: bool,
578
579 #[serde(skip_serializing_if = "is_false")]
583 deny_rule_governance: bool,
584
585 #[serde(skip_serializing_if = "is_false")]
588 package_metadata_with_dynamic_module_metadata: bool,
589
590 #[serde(skip_serializing_if = "is_false")]
593 report_move_authentication_error: bool,
594
595 #[serde(skip_serializing_if = "is_false")]
600 consensus_enable_sliding_window_leader_schedule: bool,
601
602 #[serde(skip_serializing_if = "is_false")]
607 consensus_enable_absolute_score_leader_schedule: bool,
608}
609
610fn is_true(b: &bool) -> bool {
611 *b
612}
613
614fn is_false(b: &bool) -> bool {
615 !b
616}
617
618#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
620pub enum ConsensusTransactionOrdering {
621 #[default]
624 None,
625 ByGasPrice,
627}
628
629impl ConsensusTransactionOrdering {
630 pub fn is_none(&self) -> bool {
631 matches!(self, ConsensusTransactionOrdering::None)
632 }
633}
634
635#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
637pub enum PerObjectCongestionControlMode {
638 #[default]
639 None, TotalGasBudget, TotalTxCount, }
643
644impl PerObjectCongestionControlMode {
645 pub fn is_none(&self) -> bool {
646 matches!(self, PerObjectCongestionControlMode::None)
647 }
648}
649
650#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
652pub enum ConsensusChoice {
653 #[deprecated(note = "Mysticeti was replaced by Starfish")]
656 MysticetiDeprecated,
657 #[default]
658 Starfish,
659}
660
661#[expect(deprecated)]
662impl ConsensusChoice {
663 fn mysticeti_deprecated() -> Self {
670 ConsensusChoice::MysticetiDeprecated
671 }
672
673 pub fn is_mysticeti_deprecated(&self) -> bool {
674 matches!(self, ConsensusChoice::MysticetiDeprecated)
675 }
676 pub fn is_starfish(&self) -> bool {
677 matches!(self, ConsensusChoice::Starfish)
678 }
679}
680
681#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
683pub enum ConsensusNetwork {
684 #[default]
685 Tonic,
686}
687
688impl ConsensusNetwork {
689 pub fn is_tonic(&self) -> bool {
690 matches!(self, ConsensusNetwork::Tonic)
691 }
692}
693
694#[skip_serializing_none]
728#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
729pub struct ProtocolConfig {
730 pub version: ProtocolVersion,
731
732 feature_flags: FeatureFlags,
733
734 max_tx_size_bytes: Option<u64>,
739
740 max_input_objects: Option<u64>,
743
744 max_size_written_objects: Option<u64>,
749 max_size_written_objects_system_tx: Option<u64>,
753
754 max_serialized_tx_effects_size_bytes: Option<u64>,
756
757 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
759
760 max_gas_payment_objects: Option<u32>,
762
763 max_modules_in_publish: Option<u32>,
765
766 max_package_dependencies: Option<u32>,
768
769 max_arguments: Option<u32>,
772
773 max_type_arguments: Option<u32>,
775
776 max_type_argument_depth: Option<u32>,
778
779 max_pure_argument_size: Option<u32>,
781
782 max_programmable_tx_commands: Option<u32>,
784
785 move_binary_format_version: Option<u32>,
791 min_move_binary_format_version: Option<u32>,
792
793 binary_module_handles: Option<u16>,
795 binary_struct_handles: Option<u16>,
796 binary_function_handles: Option<u16>,
797 binary_function_instantiations: Option<u16>,
798 binary_signatures: Option<u16>,
799 binary_constant_pool: Option<u16>,
800 binary_identifiers: Option<u16>,
801 binary_address_identifiers: Option<u16>,
802 binary_struct_defs: Option<u16>,
803 binary_struct_def_instantiations: Option<u16>,
804 binary_function_defs: Option<u16>,
805 binary_field_handles: Option<u16>,
806 binary_field_instantiations: Option<u16>,
807 binary_friend_decls: Option<u16>,
808 binary_enum_defs: Option<u16>,
809 binary_enum_def_instantiations: Option<u16>,
810 binary_variant_handles: Option<u16>,
811 binary_variant_instantiation_handles: Option<u16>,
812
813 max_move_object_size: Option<u64>,
816
817 max_move_package_size: Option<u64>,
822
823 max_publish_or_upgrade_per_ptb: Option<u64>,
826
827 max_tx_gas: Option<u64>,
829
830 max_auth_gas: Option<u64>,
832
833 max_gas_price: Option<u64>,
836
837 max_gas_computation_bucket: Option<u64>,
840
841 gas_rounding_step: Option<u64>,
843
844 max_loop_depth: Option<u64>,
846
847 max_generic_instantiation_length: Option<u64>,
850
851 max_function_parameters: Option<u64>,
854
855 max_basic_blocks: Option<u64>,
858
859 max_value_stack_size: Option<u64>,
861
862 max_type_nodes: Option<u64>,
866
867 max_push_size: Option<u64>,
870
871 max_struct_definitions: Option<u64>,
874
875 max_function_definitions: Option<u64>,
878
879 max_fields_in_struct: Option<u64>,
882
883 max_dependency_depth: Option<u64>,
886
887 max_num_event_emit: Option<u64>,
890
891 max_num_new_move_object_ids: Option<u64>,
894
895 max_num_new_move_object_ids_system_tx: Option<u64>,
898
899 max_num_deleted_move_object_ids: Option<u64>,
902
903 max_num_deleted_move_object_ids_system_tx: Option<u64>,
906
907 max_num_transferred_move_object_ids: Option<u64>,
910
911 max_num_transferred_move_object_ids_system_tx: Option<u64>,
914
915 max_event_emit_size: Option<u64>,
917
918 max_event_emit_size_total: Option<u64>,
920
921 max_move_vector_len: Option<u64>,
924
925 max_move_identifier_len: Option<u64>,
928
929 max_move_value_depth: Option<u64>,
931
932 max_move_enum_variants: Option<u64>,
935
936 max_back_edges_per_function: Option<u64>,
939
940 max_back_edges_per_module: Option<u64>,
943
944 max_verifier_meter_ticks_per_function: Option<u64>,
947
948 max_meter_ticks_per_module: Option<u64>,
951
952 max_meter_ticks_per_package: Option<u64>,
955
956 object_runtime_max_num_cached_objects: Option<u64>,
963
964 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
967
968 object_runtime_max_num_store_entries: Option<u64>,
971
972 object_runtime_max_num_store_entries_system_tx: Option<u64>,
975
976 base_tx_cost_fixed: Option<u64>,
981
982 package_publish_cost_fixed: Option<u64>,
986
987 base_tx_cost_per_byte: Option<u64>,
991
992 package_publish_cost_per_byte: Option<u64>,
994
995 obj_access_cost_read_per_byte: Option<u64>,
997
998 obj_access_cost_mutate_per_byte: Option<u64>,
1000
1001 obj_access_cost_delete_per_byte: Option<u64>,
1003
1004 obj_access_cost_verify_per_byte: Option<u64>,
1014
1015 max_type_to_layout_nodes: Option<u64>,
1017
1018 max_ptb_value_size: Option<u64>,
1020
1021 gas_model_version: Option<u64>,
1026
1027 obj_data_cost_refundable: Option<u64>,
1033
1034 obj_metadata_cost_non_refundable: Option<u64>,
1038
1039 storage_rebate_rate: Option<u64>,
1045
1046 reward_slashing_rate: Option<u64>,
1049
1050 storage_gas_price: Option<u64>,
1052
1053 base_gas_price: Option<u64>,
1055
1056 validator_target_reward: Option<u64>,
1058
1059 max_transactions_per_checkpoint: Option<u64>,
1066
1067 max_checkpoint_size_bytes: Option<u64>,
1071
1072 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1078
1079 address_from_bytes_cost_base: Option<u64>,
1084 address_to_u256_cost_base: Option<u64>,
1086 address_from_u256_cost_base: Option<u64>,
1088
1089 config_read_setting_impl_cost_base: Option<u64>,
1094 config_read_setting_impl_cost_per_byte: Option<u64>,
1095
1096 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1100 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1101 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1102 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1103 dynamic_field_add_child_object_cost_base: Option<u64>,
1106 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1107 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1108 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1109 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1112 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1113 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1114 dynamic_field_remove_child_object_cost_base: Option<u64>,
1117 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1118 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1119 dynamic_field_has_child_object_cost_base: Option<u64>,
1122 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1125 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1126 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1127
1128 event_emit_cost_base: Option<u64>,
1131 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1132 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1133 event_emit_output_cost_per_byte: Option<u64>,
1134
1135 object_borrow_uid_cost_base: Option<u64>,
1138 object_delete_impl_cost_base: Option<u64>,
1140 object_record_new_uid_cost_base: Option<u64>,
1142
1143 transfer_transfer_internal_cost_base: Option<u64>,
1146 transfer_freeze_object_cost_base: Option<u64>,
1148 transfer_share_object_cost_base: Option<u64>,
1150 transfer_receive_object_cost_base: Option<u64>,
1153
1154 tx_context_derive_id_cost_base: Option<u64>,
1157 tx_context_fresh_id_cost_base: Option<u64>,
1158 tx_context_sender_cost_base: Option<u64>,
1159 tx_context_digest_cost_base: Option<u64>,
1160 tx_context_epoch_cost_base: Option<u64>,
1161 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1162 tx_context_sponsor_cost_base: Option<u64>,
1163 tx_context_rgp_cost_base: Option<u64>,
1164 tx_context_gas_price_cost_base: Option<u64>,
1165 tx_context_gas_budget_cost_base: Option<u64>,
1166 tx_context_ids_created_cost_base: Option<u64>,
1167 tx_context_replace_cost_base: Option<u64>,
1168
1169 types_is_one_time_witness_cost_base: Option<u64>,
1172 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1173 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1174
1175 validator_validate_metadata_cost_base: Option<u64>,
1178 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1179
1180 crypto_invalid_arguments_cost: Option<u64>,
1182 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1184 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1185 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1186
1187 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1189 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1190 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1191
1192 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1194 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1195 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1196 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1197 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1198 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1199
1200 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1202
1203 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1205 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1206 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1207 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1208 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1209 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1210
1211 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1213 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1214 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1215 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1216 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1217 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1218
1219 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1221 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1222 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1223 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1224 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1225 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1226
1227 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1229 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1230 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1231
1232 ed25519_ed25519_verify_cost_base: Option<u64>,
1234 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1235 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1236
1237 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1239 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1240
1241 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1243 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1244 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1245 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1246 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1247
1248 hash_blake2b256_cost_base: Option<u64>,
1250 hash_blake2b256_data_cost_per_byte: Option<u64>,
1251 hash_blake2b256_data_cost_per_block: Option<u64>,
1252
1253 hash_keccak256_cost_base: Option<u64>,
1255 hash_keccak256_data_cost_per_byte: Option<u64>,
1256 hash_keccak256_data_cost_per_block: Option<u64>,
1257
1258 poseidon_bn254_cost_base: Option<u64>,
1260 poseidon_bn254_cost_per_block: Option<u64>,
1261
1262 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1264 group_ops_bls12381_decode_g1_cost: Option<u64>,
1265 group_ops_bls12381_decode_g2_cost: Option<u64>,
1266 group_ops_bls12381_decode_gt_cost: Option<u64>,
1267 group_ops_bls12381_scalar_add_cost: Option<u64>,
1268 group_ops_bls12381_g1_add_cost: Option<u64>,
1269 group_ops_bls12381_g2_add_cost: Option<u64>,
1270 group_ops_bls12381_gt_add_cost: Option<u64>,
1271 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1272 group_ops_bls12381_g1_sub_cost: Option<u64>,
1273 group_ops_bls12381_g2_sub_cost: Option<u64>,
1274 group_ops_bls12381_gt_sub_cost: Option<u64>,
1275 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1276 group_ops_bls12381_g1_mul_cost: Option<u64>,
1277 group_ops_bls12381_g2_mul_cost: Option<u64>,
1278 group_ops_bls12381_gt_mul_cost: Option<u64>,
1279 group_ops_bls12381_scalar_div_cost: Option<u64>,
1280 group_ops_bls12381_g1_div_cost: Option<u64>,
1281 group_ops_bls12381_g2_div_cost: Option<u64>,
1282 group_ops_bls12381_gt_div_cost: Option<u64>,
1283 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1284 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1285 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1286 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1287 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1288 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1289 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1290 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1291 group_ops_bls12381_msm_max_len: Option<u32>,
1292 group_ops_bls12381_pairing_cost: Option<u64>,
1293 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1294 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1295 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1296 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1297 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1298
1299 hmac_hmac_sha3_256_cost_base: Option<u64>,
1301 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1302 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1303
1304 #[deprecated]
1306 check_zklogin_id_cost_base: Option<u64>,
1307 #[deprecated]
1309 check_zklogin_issuer_cost_base: Option<u64>,
1310
1311 vdf_verify_vdf_cost: Option<u64>,
1312 vdf_hash_to_input_cost: Option<u64>,
1313
1314 bcs_per_byte_serialized_cost: Option<u64>,
1316 bcs_legacy_min_output_size_cost: Option<u64>,
1317 bcs_failure_cost: Option<u64>,
1318
1319 hash_sha2_256_base_cost: Option<u64>,
1320 hash_sha2_256_per_byte_cost: Option<u64>,
1321 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1322 hash_sha3_256_base_cost: Option<u64>,
1323 hash_sha3_256_per_byte_cost: Option<u64>,
1324 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1325 type_name_get_base_cost: Option<u64>,
1326 type_name_get_per_byte_cost: Option<u64>,
1327
1328 string_check_utf8_base_cost: Option<u64>,
1329 string_check_utf8_per_byte_cost: Option<u64>,
1330 string_is_char_boundary_base_cost: Option<u64>,
1331 string_sub_string_base_cost: Option<u64>,
1332 string_sub_string_per_byte_cost: Option<u64>,
1333 string_index_of_base_cost: Option<u64>,
1334 string_index_of_per_byte_pattern_cost: Option<u64>,
1335 string_index_of_per_byte_searched_cost: Option<u64>,
1336
1337 vector_empty_base_cost: Option<u64>,
1338 vector_length_base_cost: Option<u64>,
1339 vector_push_back_base_cost: Option<u64>,
1340 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1341 vector_borrow_base_cost: Option<u64>,
1342 vector_pop_back_base_cost: Option<u64>,
1343 vector_destroy_empty_base_cost: Option<u64>,
1344 vector_swap_base_cost: Option<u64>,
1345 debug_print_base_cost: Option<u64>,
1346 debug_print_stack_trace_base_cost: Option<u64>,
1347
1348 execution_version: Option<u64>,
1350
1351 consensus_bad_nodes_stake_threshold: Option<u64>,
1355
1356 #[deprecated]
1357 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1358 #[deprecated]
1362 max_age_of_jwk_in_epochs: Option<u64>,
1363
1364 random_beacon_reduction_allowed_delta: Option<u16>,
1368
1369 random_beacon_reduction_lower_bound: Option<u32>,
1372
1373 random_beacon_dkg_timeout_round: Option<u32>,
1376
1377 random_beacon_min_round_interval_ms: Option<u64>,
1379
1380 random_beacon_dkg_version: Option<u64>,
1384
1385 consensus_max_transaction_size_bytes: Option<u64>,
1390 consensus_max_transactions_in_block_bytes: Option<u64>,
1392 consensus_max_num_transactions_in_block: Option<u64>,
1394
1395 max_deferral_rounds_for_congestion_control: Option<u64>,
1399
1400 min_checkpoint_interval_ms: Option<u64>,
1402
1403 checkpoint_rate_window_size: Option<u64>,
1413
1414 checkpoint_summary_version_specific_data: Option<u64>,
1416
1417 max_soft_bundle_size: Option<u64>,
1420
1421 bridge_should_try_to_finalize_committee: Option<bool>,
1426
1427 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1433
1434 max_committee_members_count: Option<u64>,
1438
1439 consensus_gc_depth: Option<u32>,
1442
1443 consensus_max_acknowledgments_per_block: Option<u32>,
1449
1450 max_congestion_limit_overshoot_per_commit: Option<u64>,
1455
1456 max_concurrent_execution_workers: Option<u16>,
1463
1464 scorer_version: Option<u16>,
1473
1474 auth_context_digest_cost_base: Option<u64>,
1477 auth_context_tx_data_bytes_cost_base: Option<u64>,
1479 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1480 auth_context_tx_commands_cost_base: Option<u64>,
1482 auth_context_tx_commands_cost_per_byte: Option<u64>,
1483 auth_context_tx_inputs_cost_base: Option<u64>,
1485 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1486 auth_context_replace_cost_base: Option<u64>,
1489 auth_context_replace_cost_per_byte: Option<u64>,
1490 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1494
1495 consensus_commits_per_schedule: Option<u32>,
1498
1499 min_validator_count: Option<u64>,
1502
1503 max_validator_count: Option<u64>,
1507
1508 min_validator_joining_stake: Option<u64>,
1512
1513 validator_low_stake_threshold: Option<u64>,
1518
1519 validator_very_low_stake_threshold: Option<u64>,
1523
1524 validator_low_stake_grace_period: Option<u64>,
1528
1529 consensus_leader_schedule_window_size: Option<u32>,
1533}
1534
1535impl ProtocolConfig {
1537 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1550 self.feature_flags
1551 .disable_invariant_violation_check_in_swap_loc
1552 }
1553
1554 pub fn no_extraneous_module_bytes(&self) -> bool {
1555 self.feature_flags.no_extraneous_module_bytes
1556 }
1557
1558 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1559 self.feature_flags.consensus_transaction_ordering
1560 }
1561
1562 pub fn dkg_version(&self) -> u64 {
1563 self.random_beacon_dkg_version.unwrap_or(1)
1565 }
1566
1567 pub fn hardened_otw_check(&self) -> bool {
1568 self.feature_flags.hardened_otw_check
1569 }
1570
1571 pub fn enable_poseidon(&self) -> bool {
1572 self.feature_flags.enable_poseidon
1573 }
1574
1575 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1576 self.feature_flags.enable_group_ops_native_function_msm
1577 }
1578
1579 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1580 self.feature_flags.per_object_congestion_control_mode
1581 }
1582
1583 pub fn consensus_choice(&self) -> ConsensusChoice {
1584 self.feature_flags.consensus_choice
1585 }
1586
1587 pub fn consensus_network(&self) -> ConsensusNetwork {
1588 self.feature_flags.consensus_network
1589 }
1590
1591 pub fn enable_vdf(&self) -> bool {
1592 self.feature_flags.enable_vdf
1593 }
1594
1595 pub fn passkey_auth(&self) -> bool {
1596 self.feature_flags.passkey_auth
1597 }
1598
1599 pub fn max_transaction_size_bytes(&self) -> u64 {
1600 self.consensus_max_transaction_size_bytes
1602 .unwrap_or(256 * 1024)
1603 }
1604
1605 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1606 if cfg!(msim) {
1607 256 * 1024
1608 } else {
1609 self.consensus_max_transactions_in_block_bytes
1610 .unwrap_or(512 * 1024)
1611 }
1612 }
1613
1614 pub fn max_num_transactions_in_block(&self) -> u64 {
1615 if cfg!(msim) {
1616 8
1617 } else {
1618 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1619 }
1620 }
1621
1622 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1623 self.feature_flags.rethrow_serialization_type_layout_errors
1624 }
1625
1626 pub fn relocate_event_module(&self) -> bool {
1627 self.feature_flags.relocate_event_module
1628 }
1629
1630 pub fn protocol_defined_base_fee(&self) -> bool {
1631 self.feature_flags.protocol_defined_base_fee
1632 }
1633
1634 pub fn uncompressed_g1_group_elements(&self) -> bool {
1635 self.feature_flags.uncompressed_g1_group_elements
1636 }
1637
1638 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1639 self.feature_flags
1640 .disallow_new_modules_in_deps_only_packages
1641 }
1642
1643 pub fn native_charging_v2(&self) -> bool {
1644 self.feature_flags.native_charging_v2
1645 }
1646
1647 pub fn consensus_round_prober(&self) -> bool {
1648 self.feature_flags.consensus_round_prober
1649 }
1650
1651 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1652 self.feature_flags
1653 .consensus_distributed_vote_scoring_strategy
1654 }
1655
1656 pub fn gc_depth(&self) -> u32 {
1657 if cfg!(msim) {
1658 min(5, self.consensus_gc_depth.unwrap_or(0))
1660 } else {
1661 self.consensus_gc_depth.unwrap_or(0)
1662 }
1663 }
1664
1665 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1666 let res = self.feature_flags.consensus_linearize_subdag_v2;
1667 assert!(
1668 !res || self.gc_depth() > 0,
1669 "The consensus linearize sub dag V2 requires GC to be enabled"
1670 );
1671 res
1672 }
1673
1674 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1675 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1676 }
1677
1678 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1679 2 * committee_size
1680 }
1681
1682 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1683 committee_size
1684 }
1685
1686 pub fn variant_nodes(&self) -> bool {
1687 self.feature_flags.variant_nodes
1688 }
1689
1690 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1691 self.feature_flags.consensus_smart_ancestor_selection
1692 }
1693
1694 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1695 self.feature_flags
1696 .consensus_round_prober_probe_accepted_rounds
1697 }
1698
1699 pub fn consensus_zstd_compression(&self) -> bool {
1700 self.feature_flags.consensus_zstd_compression
1701 }
1702
1703 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1704 self.feature_flags
1705 .congestion_control_min_free_execution_slot
1706 }
1707
1708 pub fn accept_passkey_in_multisig(&self) -> bool {
1709 self.feature_flags.accept_passkey_in_multisig
1710 }
1711
1712 pub fn consensus_batched_block_sync(&self) -> bool {
1713 self.feature_flags.consensus_batched_block_sync
1714 }
1715
1716 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1719 self.feature_flags
1720 .congestion_control_gas_price_feedback_mechanism
1721 }
1722
1723 pub fn validate_identifier_inputs(&self) -> bool {
1724 self.feature_flags.validate_identifier_inputs
1725 }
1726
1727 pub fn minimize_child_object_mutations(&self) -> bool {
1728 self.feature_flags.minimize_child_object_mutations
1729 }
1730
1731 pub fn dependency_linkage_error(&self) -> bool {
1732 self.feature_flags.dependency_linkage_error
1733 }
1734
1735 pub fn additional_multisig_checks(&self) -> bool {
1736 self.feature_flags.additional_multisig_checks
1737 }
1738
1739 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1740 0
1743 }
1744
1745 pub fn normalize_ptb_arguments(&self) -> bool {
1746 self.feature_flags.normalize_ptb_arguments
1747 }
1748
1749 pub fn select_committee_from_eligible_validators(&self) -> bool {
1750 let res = self.feature_flags.select_committee_from_eligible_validators;
1751 assert!(
1752 !res || (self.protocol_defined_base_fee()
1753 && self.max_committee_members_count_as_option().is_some()),
1754 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1755 );
1756 res
1757 }
1758
1759 pub fn track_non_committee_eligible_validators(&self) -> bool {
1760 self.feature_flags.track_non_committee_eligible_validators
1761 }
1762
1763 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1764 let res = self
1765 .feature_flags
1766 .select_committee_supporting_next_epoch_version;
1767 assert!(
1768 !res || (self.track_non_committee_eligible_validators()
1769 && self.select_committee_from_eligible_validators()),
1770 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1771 );
1772 res
1773 }
1774
1775 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1776 let res = self
1777 .feature_flags
1778 .consensus_median_timestamp_with_checkpoint_enforcement;
1779 assert!(
1780 !res || self.gc_depth() > 0,
1781 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1782 );
1783 res
1784 }
1785
1786 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1787 self.feature_flags
1788 .consensus_commit_transactions_only_for_traversed_headers
1789 }
1790
1791 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1794 self.feature_flags
1795 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1796 }
1797
1798 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1801 self.feature_flags
1802 .separate_gas_price_feedback_mechanism_for_randomness
1803 }
1804
1805 pub fn metadata_in_module_bytes(&self) -> bool {
1806 self.feature_flags.metadata_in_module_bytes
1807 }
1808
1809 pub fn publish_package_metadata(&self) -> bool {
1810 self.feature_flags.publish_package_metadata
1811 }
1812
1813 pub fn enable_move_authentication(&self) -> bool {
1814 self.feature_flags.enable_move_authentication
1815 }
1816
1817 pub fn additional_borrow_checks(&self) -> bool {
1818 self.feature_flags.additional_borrow_checks
1819 }
1820
1821 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1822 let enable_move_authentication_for_sponsor =
1823 self.feature_flags.enable_move_authentication_for_sponsor;
1824 assert!(
1825 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1826 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1827 );
1828 enable_move_authentication_for_sponsor
1829 }
1830
1831 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1832 self.feature_flags.pass_validator_scores_to_advance_epoch
1833 }
1834
1835 pub fn calculate_validator_scores(&self) -> bool {
1836 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1837 assert!(
1838 !calculate_validator_scores || self.scorer_version.is_some(),
1839 "calculate_validator_scores requires scorer_version to be set"
1840 );
1841 calculate_validator_scores
1842 }
1843
1844 pub fn adjust_rewards_by_score(&self) -> bool {
1845 let adjust = self.feature_flags.adjust_rewards_by_score;
1846 assert!(
1847 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1848 "adjust_rewards_by_score requires scorer_version to be set"
1849 );
1850 adjust
1851 }
1852
1853 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1854 let pass = self
1855 .feature_flags
1856 .pass_calculated_validator_scores_to_advance_epoch;
1857 assert!(
1858 !pass
1859 || (self.pass_validator_scores_to_advance_epoch()
1860 && self.calculate_validator_scores()),
1861 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1862 );
1863 pass
1864 }
1865 pub fn consensus_fast_commit_sync(&self) -> bool {
1866 let res = self.feature_flags.consensus_fast_commit_sync;
1867 assert!(
1868 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1869 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1870 );
1871 res
1872 }
1873
1874 pub fn consensus_block_restrictions(&self) -> bool {
1875 self.feature_flags.consensus_block_restrictions
1876 }
1877
1878 pub fn move_native_tx_context(&self) -> bool {
1879 self.feature_flags.move_native_tx_context
1880 }
1881
1882 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1883 let pre_consensus_sponsor_only_move_authentication = self
1884 .feature_flags
1885 .pre_consensus_sponsor_only_move_authentication;
1886 if pre_consensus_sponsor_only_move_authentication {
1887 assert!(
1888 self.enable_move_authentication(),
1889 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1890 );
1891 assert!(
1892 self.enable_move_authentication_for_sponsor(),
1893 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1894 );
1895 }
1896 pre_consensus_sponsor_only_move_authentication
1897 }
1898
1899 pub fn consensus_starfish_speed(&self) -> bool {
1900 let res = self.feature_flags.consensus_starfish_speed;
1901 assert!(
1902 !res || self.consensus_fast_commit_sync(),
1903 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1904 );
1905 res
1906 }
1907
1908 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1909 self.feature_flags.always_advance_dkg_to_resolution
1910 }
1911
1912 pub fn enable_pcool_flow(&self) -> bool {
1913 self.feature_flags.enable_pcool_flow
1914 }
1915
1916 pub fn validator_metadata_verify_v2(&self) -> bool {
1917 self.feature_flags.validator_metadata_verify_v2
1918 }
1919
1920 pub fn commits_per_schedule(&self) -> u32 {
1921 let commits_per_schedule = if cfg!(msim) {
1922 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
1924 } else {
1925 self.consensus_commits_per_schedule.unwrap_or(300)
1926 };
1927 assert!(
1928 commits_per_schedule > 0,
1929 "consensus_commits_per_schedule must be greater than 0"
1930 );
1931 commits_per_schedule
1932 }
1933
1934 pub fn leader_schedule_window_size(&self) -> u32 {
1935 if cfg!(msim) {
1936 min(
1939 20,
1940 self.consensus_leader_schedule_window_size.unwrap_or(600),
1941 )
1942 } else {
1943 self.consensus_leader_schedule_window_size.unwrap_or(600)
1944 }
1945 }
1946
1947 pub fn consensus_enable_sliding_window_leader_schedule(&self) -> bool {
1948 let res = self
1949 .feature_flags
1950 .consensus_enable_sliding_window_leader_schedule;
1951 assert!(
1952 !res || self.leader_schedule_window_size() >= self.commits_per_schedule(),
1953 "consensus_enable_sliding_window_leader_schedule requires window_size >= commits_per_schedule"
1954 );
1955 res
1956 }
1957
1958 pub fn consensus_enable_absolute_score_leader_schedule(&self) -> bool {
1959 self.feature_flags
1960 .consensus_enable_absolute_score_leader_schedule
1961 }
1962
1963 pub fn deny_rule_governance(&self) -> bool {
1964 self.feature_flags.deny_rule_governance
1965 }
1966
1967 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
1968 let res = self
1969 .feature_flags
1970 .package_metadata_with_dynamic_module_metadata;
1971 assert!(
1972 !res || self.publish_package_metadata(),
1973 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
1974 );
1975 res
1976 }
1977
1978 pub fn report_move_authentication_error(&self) -> bool {
1979 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
1980 assert!(
1981 !report_move_authentication_error || self.enable_move_authentication(),
1982 "report_move_authentication_error requires enable_move_authentication to be set"
1983 );
1984 report_move_authentication_error
1985 }
1986
1987 pub fn concurrent_execution_workers(&self) -> Option<u16> {
1991 let res = self.max_concurrent_execution_workers;
1992 assert!(
1993 res.is_none() || self.enable_pcool_flow(),
1994 "max_concurrent_execution_workers requires enable_pcool_flow to be enabled"
1995 );
1996 assert!(
1997 res.is_none()
1998 || self
1999 .max_accumulated_txn_cost_per_object_in_mysticeti_commit
2000 .is_some(),
2001 "max_concurrent_execution_workers requires per-object congestion control \
2002 (max_accumulated_txn_cost_per_object_in_mysticeti_commit) to be enabled"
2003 );
2004 assert!(
2005 res.is_none() || self.congestion_control_gas_price_feedback_mechanism(),
2006 "max_concurrent_execution_workers requires the gas price feedback mechanism \
2007 (congestion_control_gas_price_feedback_mechanism), which carries the suggested \
2008 gas price of an execution-worker congestion cancellation"
2009 );
2010 assert!(
2011 res.is_none() || !self.separate_gas_price_feedback_mechanism_for_randomness(),
2012 "max_concurrent_execution_workers implies a single congestion tracker and suggested \
2013 gas price calculator for all transactions, which is incompatible with \
2014 separate_gas_price_feedback_mechanism_for_randomness"
2015 );
2016 assert!(
2017 res != Some(0),
2018 "max_concurrent_execution_workers must be positive when set"
2019 );
2020 res
2021 }
2022}
2023
2024#[cfg(not(msim))]
2025static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2026
2027#[cfg(msim)]
2029thread_local! {
2030 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2031}
2032
2033impl ProtocolConfig {
2035 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2038 assert!(
2040 version >= ProtocolVersion::MIN,
2041 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2042 version,
2043 ProtocolVersion::MIN.0,
2044 );
2045 assert!(
2046 version <= ProtocolVersion::MAX_ALLOWED,
2047 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2048 version,
2049 ProtocolVersion::MAX_ALLOWED.0,
2050 );
2051
2052 let mut ret = Self::get_for_version_impl(version, chain);
2053 ret.version = version;
2054
2055 ret = CONFIG_OVERRIDE.with(|ovr| {
2056 if let Some(override_fn) = &*ovr.borrow() {
2057 warn!(
2058 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2059 );
2060 override_fn(version, ret)
2061 } else {
2062 ret
2063 }
2064 });
2065
2066 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2067 warn!(
2068 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2069 );
2070
2071 let overrides: ProtocolConfigOptional =
2073 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
2074 .expect("failed to parse ProtocolConfig override env variables");
2075 overrides.apply_to(&mut ret);
2076
2077 let feature_flag_overrides: FeatureFlagsOptional =
2079 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
2080 .expect("failed to parse ProtocolConfig feature flags override env variables");
2081
2082 feature_flag_overrides.apply_to(&mut ret.feature_flags);
2083 }
2084
2085 ret
2086 }
2087
2088 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2091 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2092 let mut ret = Self::get_for_version_impl(version, chain);
2093 ret.version = version;
2094 Some(ret)
2095 } else {
2096 None
2097 }
2098 }
2099
2100 #[cfg(not(msim))]
2101 pub fn poison_get_for_min_version() {
2102 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2103 }
2104
2105 #[cfg(not(msim))]
2106 fn load_poison_get_for_min_version() -> bool {
2107 POISON_VERSION_METHODS.load(Ordering::Relaxed)
2108 }
2109
2110 #[cfg(msim)]
2111 pub fn poison_get_for_min_version() {
2112 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2113 }
2114
2115 #[cfg(msim)]
2116 fn load_poison_get_for_min_version() -> bool {
2117 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2118 }
2119
2120 pub fn convert_type_argument_error(&self) -> bool {
2121 self.feature_flags.convert_type_argument_error
2122 }
2123
2124 pub fn get_for_min_version() -> Self {
2128 if Self::load_poison_get_for_min_version() {
2129 panic!("get_for_min_version called on validator");
2130 }
2131 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2132 }
2133
2134 #[expect(non_snake_case)]
2145 pub fn get_for_max_version_UNSAFE() -> Self {
2146 if Self::load_poison_get_for_min_version() {
2147 panic!("get_for_max_version_UNSAFE called on validator");
2148 }
2149 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2150 }
2151
2152 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2153 #[cfg(msim)]
2154 {
2155 if version > ProtocolVersion::MAX {
2157 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2158 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2159 return config;
2160 }
2161 }
2162
2163 let mut cfg = Self {
2167 version,
2168
2169 feature_flags: Default::default(),
2170
2171 max_tx_size_bytes: Some(128 * 1024),
2172 max_input_objects: Some(2048),
2175 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2176 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2177 max_gas_payment_objects: Some(256),
2178 max_modules_in_publish: Some(64),
2179 max_package_dependencies: Some(32),
2180 max_arguments: Some(512),
2181 max_type_arguments: Some(16),
2182 max_type_argument_depth: Some(16),
2183 max_pure_argument_size: Some(16 * 1024),
2184 max_programmable_tx_commands: Some(1024),
2185 move_binary_format_version: Some(7),
2186 min_move_binary_format_version: Some(6),
2187 binary_module_handles: Some(100),
2188 binary_struct_handles: Some(300),
2189 binary_function_handles: Some(1500),
2190 binary_function_instantiations: Some(750),
2191 binary_signatures: Some(1000),
2192 binary_constant_pool: Some(4000),
2193 binary_identifiers: Some(10000),
2194 binary_address_identifiers: Some(100),
2195 binary_struct_defs: Some(200),
2196 binary_struct_def_instantiations: Some(100),
2197 binary_function_defs: Some(1000),
2198 binary_field_handles: Some(500),
2199 binary_field_instantiations: Some(250),
2200 binary_friend_decls: Some(100),
2201 binary_enum_defs: None,
2202 binary_enum_def_instantiations: None,
2203 binary_variant_handles: None,
2204 binary_variant_instantiation_handles: None,
2205 max_move_object_size: Some(250 * 1024),
2206 max_move_package_size: Some(100 * 1024),
2207 max_publish_or_upgrade_per_ptb: Some(5),
2208 max_auth_gas: None,
2210 max_tx_gas: Some(50_000_000_000),
2212 max_gas_price: Some(100_000),
2213 max_gas_computation_bucket: Some(5_000_000),
2214 max_loop_depth: Some(5),
2215 max_generic_instantiation_length: Some(32),
2216 max_function_parameters: Some(128),
2217 max_basic_blocks: Some(1024),
2218 max_value_stack_size: Some(1024),
2219 max_type_nodes: Some(256),
2220 max_push_size: Some(10000),
2221 max_struct_definitions: Some(200),
2222 max_function_definitions: Some(1000),
2223 max_fields_in_struct: Some(32),
2224 max_dependency_depth: Some(100),
2225 max_num_event_emit: Some(1024),
2226 max_num_new_move_object_ids: Some(2048),
2227 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2228 max_num_deleted_move_object_ids: Some(2048),
2229 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2230 max_num_transferred_move_object_ids: Some(2048),
2231 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2232 max_event_emit_size: Some(250 * 1024),
2233 max_move_vector_len: Some(256 * 1024),
2234 max_type_to_layout_nodes: None,
2235 max_ptb_value_size: None,
2236
2237 max_back_edges_per_function: Some(10_000),
2238 max_back_edges_per_module: Some(10_000),
2239
2240 max_verifier_meter_ticks_per_function: Some(16_000_000),
2241
2242 max_meter_ticks_per_module: Some(16_000_000),
2243 max_meter_ticks_per_package: Some(16_000_000),
2244
2245 object_runtime_max_num_cached_objects: Some(1000),
2246 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2247 object_runtime_max_num_store_entries: Some(1000),
2248 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2249 base_tx_cost_fixed: Some(1_000),
2251 package_publish_cost_fixed: Some(1_000),
2252 base_tx_cost_per_byte: Some(0),
2253 package_publish_cost_per_byte: Some(80),
2254 obj_access_cost_read_per_byte: Some(15),
2255 obj_access_cost_mutate_per_byte: Some(40),
2256 obj_access_cost_delete_per_byte: Some(40),
2257 obj_access_cost_verify_per_byte: Some(200),
2258 obj_data_cost_refundable: Some(100),
2259 obj_metadata_cost_non_refundable: Some(50),
2260 gas_model_version: Some(1),
2261 storage_rebate_rate: Some(10000),
2262 reward_slashing_rate: Some(10000),
2264 storage_gas_price: Some(76),
2265 base_gas_price: None,
2266 validator_target_reward: Some(767_000 * 1_000_000_000),
2269 max_transactions_per_checkpoint: Some(10_000),
2270 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2271
2272 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2274
2275 address_from_bytes_cost_base: Some(52),
2279 address_to_u256_cost_base: Some(52),
2281 address_from_u256_cost_base: Some(52),
2283
2284 config_read_setting_impl_cost_base: Some(100),
2287 config_read_setting_impl_cost_per_byte: Some(40),
2288
2289 dynamic_field_hash_type_and_key_cost_base: Some(100),
2293 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2294 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2295 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2296 dynamic_field_add_child_object_cost_base: Some(100),
2299 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2300 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2301 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2302 dynamic_field_borrow_child_object_cost_base: Some(100),
2305 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2306 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2307 dynamic_field_remove_child_object_cost_base: Some(100),
2310 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2311 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2312 dynamic_field_has_child_object_cost_base: Some(100),
2315 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2318 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2319 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2320
2321 event_emit_cost_base: Some(52),
2324 event_emit_value_size_derivation_cost_per_byte: Some(2),
2325 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2326 event_emit_output_cost_per_byte: Some(10),
2327
2328 object_borrow_uid_cost_base: Some(52),
2331 object_delete_impl_cost_base: Some(52),
2333 object_record_new_uid_cost_base: Some(52),
2335
2336 transfer_transfer_internal_cost_base: Some(52),
2340 transfer_freeze_object_cost_base: Some(52),
2342 transfer_share_object_cost_base: Some(52),
2344 transfer_receive_object_cost_base: Some(52),
2345
2346 tx_context_derive_id_cost_base: Some(52),
2350 tx_context_fresh_id_cost_base: None,
2351 tx_context_sender_cost_base: None,
2352 tx_context_digest_cost_base: None,
2353 tx_context_epoch_cost_base: None,
2354 tx_context_epoch_timestamp_ms_cost_base: None,
2355 tx_context_sponsor_cost_base: None,
2356 tx_context_rgp_cost_base: None,
2357 tx_context_gas_price_cost_base: None,
2358 tx_context_gas_budget_cost_base: None,
2359 tx_context_ids_created_cost_base: None,
2360 tx_context_replace_cost_base: None,
2361
2362 types_is_one_time_witness_cost_base: Some(52),
2365 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2366 types_is_one_time_witness_type_cost_per_byte: Some(2),
2367
2368 validator_validate_metadata_cost_base: Some(52),
2372 validator_validate_metadata_data_cost_per_byte: Some(2),
2373
2374 crypto_invalid_arguments_cost: Some(100),
2376 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2378 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2379 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2380
2381 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2383 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2384 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2385
2386 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2388 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2389 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2390 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2391 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2392 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2393
2394 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2396
2397 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2399 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2400 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2401 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2402 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2403 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2404
2405 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2407 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2408 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2409 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2410 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2411 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2412
2413 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2415 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2416 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2417 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2418 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2419 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2420
2421 ecvrf_ecvrf_verify_cost_base: Some(52),
2423 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2424 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2425
2426 ed25519_ed25519_verify_cost_base: Some(52),
2428 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2429 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2430
2431 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2433 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2434
2435 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2437 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2438 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2439 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2440 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2441
2442 hash_blake2b256_cost_base: Some(52),
2444 hash_blake2b256_data_cost_per_byte: Some(2),
2445 hash_blake2b256_data_cost_per_block: Some(2),
2446 hash_keccak256_cost_base: Some(52),
2448 hash_keccak256_data_cost_per_byte: Some(2),
2449 hash_keccak256_data_cost_per_block: Some(2),
2450
2451 poseidon_bn254_cost_base: None,
2452 poseidon_bn254_cost_per_block: None,
2453
2454 hmac_hmac_sha3_256_cost_base: Some(52),
2456 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2457 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2458
2459 group_ops_bls12381_decode_scalar_cost: Some(52),
2461 group_ops_bls12381_decode_g1_cost: Some(52),
2462 group_ops_bls12381_decode_g2_cost: Some(52),
2463 group_ops_bls12381_decode_gt_cost: Some(52),
2464 group_ops_bls12381_scalar_add_cost: Some(52),
2465 group_ops_bls12381_g1_add_cost: Some(52),
2466 group_ops_bls12381_g2_add_cost: Some(52),
2467 group_ops_bls12381_gt_add_cost: Some(52),
2468 group_ops_bls12381_scalar_sub_cost: Some(52),
2469 group_ops_bls12381_g1_sub_cost: Some(52),
2470 group_ops_bls12381_g2_sub_cost: Some(52),
2471 group_ops_bls12381_gt_sub_cost: Some(52),
2472 group_ops_bls12381_scalar_mul_cost: Some(52),
2473 group_ops_bls12381_g1_mul_cost: Some(52),
2474 group_ops_bls12381_g2_mul_cost: Some(52),
2475 group_ops_bls12381_gt_mul_cost: Some(52),
2476 group_ops_bls12381_scalar_div_cost: Some(52),
2477 group_ops_bls12381_g1_div_cost: Some(52),
2478 group_ops_bls12381_g2_div_cost: Some(52),
2479 group_ops_bls12381_gt_div_cost: Some(52),
2480 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2481 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2482 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2483 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2484 group_ops_bls12381_g1_msm_base_cost: Some(52),
2485 group_ops_bls12381_g2_msm_base_cost: Some(52),
2486 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2487 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2488 group_ops_bls12381_msm_max_len: Some(32),
2489 group_ops_bls12381_pairing_cost: Some(52),
2490 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2491 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2492 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2493 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2494 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2495
2496 #[allow(deprecated)]
2498 check_zklogin_id_cost_base: Some(200),
2499 #[allow(deprecated)]
2500 check_zklogin_issuer_cost_base: Some(200),
2502
2503 vdf_verify_vdf_cost: None,
2504 vdf_hash_to_input_cost: None,
2505
2506 bcs_per_byte_serialized_cost: Some(2),
2507 bcs_legacy_min_output_size_cost: Some(1),
2508 bcs_failure_cost: Some(52),
2509 hash_sha2_256_base_cost: Some(52),
2510 hash_sha2_256_per_byte_cost: Some(2),
2511 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2512 hash_sha3_256_base_cost: Some(52),
2513 hash_sha3_256_per_byte_cost: Some(2),
2514 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2515 type_name_get_base_cost: Some(52),
2516 type_name_get_per_byte_cost: Some(2),
2517 string_check_utf8_base_cost: Some(52),
2518 string_check_utf8_per_byte_cost: Some(2),
2519 string_is_char_boundary_base_cost: Some(52),
2520 string_sub_string_base_cost: Some(52),
2521 string_sub_string_per_byte_cost: Some(2),
2522 string_index_of_base_cost: Some(52),
2523 string_index_of_per_byte_pattern_cost: Some(2),
2524 string_index_of_per_byte_searched_cost: Some(2),
2525 vector_empty_base_cost: Some(52),
2526 vector_length_base_cost: Some(52),
2527 vector_push_back_base_cost: Some(52),
2528 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2529 vector_borrow_base_cost: Some(52),
2530 vector_pop_back_base_cost: Some(52),
2531 vector_destroy_empty_base_cost: Some(52),
2532 vector_swap_base_cost: Some(52),
2533 debug_print_base_cost: Some(52),
2534 debug_print_stack_trace_base_cost: Some(52),
2535
2536 max_size_written_objects: Some(5 * 1000 * 1000),
2537 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2540
2541 max_move_identifier_len: Some(128),
2543 max_move_value_depth: Some(128),
2544 max_move_enum_variants: None,
2545
2546 gas_rounding_step: Some(1_000),
2547
2548 execution_version: Some(1),
2549
2550 max_event_emit_size_total: Some(
2553 256 * 250 * 1024, ),
2555
2556 consensus_bad_nodes_stake_threshold: Some(20),
2563
2564 #[allow(deprecated)]
2566 max_jwk_votes_per_validator_per_epoch: Some(240),
2567
2568 #[allow(deprecated)]
2569 max_age_of_jwk_in_epochs: Some(1),
2570
2571 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2575
2576 random_beacon_reduction_allowed_delta: Some(800),
2577
2578 random_beacon_reduction_lower_bound: Some(1000),
2579 random_beacon_dkg_timeout_round: Some(3000),
2580 random_beacon_min_round_interval_ms: Some(500),
2581
2582 random_beacon_dkg_version: Some(1),
2583
2584 consensus_max_num_transactions_in_block: Some(512),
2588
2589 max_deferral_rounds_for_congestion_control: Some(10),
2590
2591 min_checkpoint_interval_ms: Some(200),
2592
2593 checkpoint_rate_window_size: None,
2594
2595 checkpoint_summary_version_specific_data: Some(1),
2596
2597 max_soft_bundle_size: Some(5),
2598
2599 bridge_should_try_to_finalize_committee: None,
2600
2601 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2602
2603 max_committee_members_count: None,
2604
2605 consensus_gc_depth: None,
2606
2607 consensus_max_acknowledgments_per_block: None,
2608
2609 max_congestion_limit_overshoot_per_commit: None,
2610
2611 max_concurrent_execution_workers: None,
2612
2613 scorer_version: None,
2614
2615 auth_context_digest_cost_base: None,
2617 auth_context_tx_data_bytes_cost_base: None,
2618 auth_context_tx_data_bytes_cost_per_byte: None,
2619 auth_context_tx_commands_cost_base: None,
2620 auth_context_tx_commands_cost_per_byte: None,
2621 auth_context_tx_inputs_cost_base: None,
2622 auth_context_tx_inputs_cost_per_byte: None,
2623 auth_context_replace_cost_base: None,
2624 auth_context_replace_cost_per_byte: None,
2625 auth_context_authenticator_function_info_v1_cost_base: None,
2626 consensus_commits_per_schedule: None,
2627 min_validator_count: None,
2628 max_validator_count: None,
2629 min_validator_joining_stake: None,
2630 validator_low_stake_threshold: None,
2631 validator_very_low_stake_threshold: None,
2632 validator_low_stake_grace_period: None,
2633 consensus_leader_schedule_window_size: None,
2634 };
2637
2638 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2639
2640 {
2642 cfg.feature_flags
2643 .disable_invariant_violation_check_in_swap_loc = true;
2644 cfg.feature_flags.no_extraneous_module_bytes = true;
2645 cfg.feature_flags.hardened_otw_check = true;
2646 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2647 }
2648
2649 {
2651 #[allow(deprecated)]
2652 {
2653 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2654 }
2655 }
2656
2657 #[expect(deprecated)]
2661 {
2662 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2663 }
2664 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2666
2667 cfg.feature_flags.per_object_congestion_control_mode =
2668 PerObjectCongestionControlMode::TotalTxCount;
2669
2670 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2672
2673 if chain != Chain::Mainnet && chain != Chain::Testnet {
2675 cfg.feature_flags.enable_poseidon = true;
2676 cfg.poseidon_bn254_cost_base = Some(260);
2677 cfg.poseidon_bn254_cost_per_block = Some(10);
2678
2679 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2680
2681 cfg.feature_flags.enable_vdf = true;
2682 cfg.vdf_verify_vdf_cost = Some(1500);
2685 cfg.vdf_hash_to_input_cost = Some(100);
2686
2687 cfg.feature_flags.passkey_auth = true;
2688 }
2689
2690 for cur in 2..=version.0 {
2691 match cur {
2692 1 => unreachable!(),
2693 2 => {}
2695 3 => {
2696 cfg.feature_flags.relocate_event_module = true;
2697 }
2698 4 => {
2699 cfg.max_type_to_layout_nodes = Some(512);
2700 }
2701 5 => {
2702 cfg.feature_flags.protocol_defined_base_fee = true;
2703 cfg.base_gas_price = Some(1000);
2704
2705 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2706 cfg.feature_flags.convert_type_argument_error = true;
2707 cfg.feature_flags.native_charging_v2 = true;
2708
2709 if chain != Chain::Mainnet && chain != Chain::Testnet {
2710 cfg.feature_flags.uncompressed_g1_group_elements = true;
2711 }
2712
2713 cfg.gas_model_version = Some(2);
2714
2715 cfg.poseidon_bn254_cost_per_block = Some(388);
2716
2717 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2718 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2719 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2720 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2721 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2722 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2723 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2724 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2725
2726 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2728 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2729 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2730 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2731
2732 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2733 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2734 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2735 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2736 Some(8213);
2737 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2738 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2739 Some(9484);
2740
2741 cfg.hash_keccak256_cost_base = Some(10);
2742 cfg.hash_blake2b256_cost_base = Some(10);
2743
2744 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2746 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2747 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2748 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2749
2750 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2751 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2752 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2753 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2754
2755 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2756 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2757 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2758 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2759
2760 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2761 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2762 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2763 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2764
2765 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2766 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2767 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2768 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2769
2770 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2771 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2772
2773 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2774 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2775 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2776 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2777
2778 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2779 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2780 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2781 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2782 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2783
2784 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2785
2786 cfg.validator_validate_metadata_cost_base = Some(20000);
2787
2788 cfg.max_committee_members_count = Some(50);
2789 }
2790 6 => {
2791 cfg.max_ptb_value_size = Some(1024 * 1024);
2792 }
2793 7 => {
2794 }
2797 8 => {
2798 cfg.feature_flags.variant_nodes = true;
2799
2800 if chain != Chain::Mainnet {
2801 cfg.feature_flags.consensus_round_prober = true;
2803 cfg.feature_flags
2805 .consensus_distributed_vote_scoring_strategy = true;
2806 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2807 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2809 cfg.feature_flags
2811 .consensus_round_prober_probe_accepted_rounds = true;
2812 cfg.feature_flags.consensus_zstd_compression = true;
2814 cfg.consensus_gc_depth = Some(60);
2818 }
2819
2820 if chain != Chain::Testnet && chain != Chain::Mainnet {
2823 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2824 }
2825 }
2826 9 => {
2827 if chain != Chain::Mainnet {
2828 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2830 }
2831
2832 cfg.feature_flags.consensus_zstd_compression = true;
2834
2835 if chain != Chain::Testnet && chain != Chain::Mainnet {
2837 cfg.feature_flags.accept_passkey_in_multisig = true;
2838 }
2839
2840 cfg.bridge_should_try_to_finalize_committee = None;
2842 }
2843 10 => {
2844 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2847
2848 cfg.max_committee_members_count = Some(80);
2850
2851 cfg.feature_flags.consensus_round_prober = true;
2853 cfg.feature_flags
2855 .consensus_round_prober_probe_accepted_rounds = true;
2856 cfg.feature_flags
2858 .consensus_distributed_vote_scoring_strategy = true;
2859 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2861
2862 cfg.consensus_gc_depth = Some(60);
2867
2868 cfg.feature_flags.minimize_child_object_mutations = true;
2870
2871 if chain != Chain::Mainnet {
2872 cfg.feature_flags.consensus_batched_block_sync = true;
2874 }
2875
2876 if chain != Chain::Testnet && chain != Chain::Mainnet {
2877 cfg.feature_flags
2880 .congestion_control_gas_price_feedback_mechanism = true;
2881 }
2882
2883 cfg.feature_flags.validate_identifier_inputs = true;
2884 cfg.feature_flags.dependency_linkage_error = true;
2885 cfg.feature_flags.additional_multisig_checks = true;
2886 }
2887 11 => {
2888 }
2891 12 => {
2892 cfg.feature_flags
2895 .congestion_control_gas_price_feedback_mechanism = true;
2896
2897 cfg.feature_flags.normalize_ptb_arguments = true;
2899 }
2900 13 => {
2901 cfg.feature_flags.select_committee_from_eligible_validators = true;
2904 cfg.feature_flags.track_non_committee_eligible_validators = true;
2907
2908 if chain != Chain::Testnet && chain != Chain::Mainnet {
2909 cfg.feature_flags
2912 .select_committee_supporting_next_epoch_version = true;
2913 }
2914 }
2915 14 => {
2916 cfg.feature_flags.consensus_batched_block_sync = true;
2918
2919 if chain != Chain::Mainnet {
2920 cfg.feature_flags
2923 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2924 cfg.feature_flags
2928 .select_committee_supporting_next_epoch_version = true;
2929 }
2930 if chain != Chain::Testnet && chain != Chain::Mainnet {
2931 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2933 }
2934 }
2935 15 => {
2936 if chain != Chain::Mainnet && chain != Chain::Testnet {
2937 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2941 }
2942 }
2943 16 => {
2944 cfg.feature_flags
2947 .select_committee_supporting_next_epoch_version = true;
2948 cfg.feature_flags
2950 .consensus_commit_transactions_only_for_traversed_headers = true;
2951 }
2952 17 => {
2953 cfg.max_committee_members_count = Some(100);
2955 }
2956 18 => {
2957 if chain != Chain::Mainnet {
2958 cfg.feature_flags.passkey_auth = true;
2960 }
2961 }
2962 19 => {
2963 if chain != Chain::Testnet && chain != Chain::Mainnet {
2964 cfg.feature_flags
2967 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2968 cfg.feature_flags
2971 .separate_gas_price_feedback_mechanism_for_randomness = true;
2972 cfg.feature_flags.metadata_in_module_bytes = true;
2975 cfg.feature_flags.publish_package_metadata = true;
2976 cfg.feature_flags.enable_move_authentication = true;
2978 cfg.max_auth_gas = Some(250_000_000);
2980 cfg.transfer_receive_object_cost_base = Some(100);
2983 cfg.feature_flags.adjust_rewards_by_score = true;
2985 }
2986
2987 if chain != Chain::Mainnet {
2988 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2990
2991 cfg.feature_flags.calculate_validator_scores = true;
2993 cfg.scorer_version = Some(1);
2994 }
2995
2996 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2998
2999 cfg.feature_flags.passkey_auth = true;
3001 }
3002 20 => {
3003 if chain != Chain::Testnet && chain != Chain::Mainnet {
3004 cfg.feature_flags
3006 .pass_calculated_validator_scores_to_advance_epoch = true;
3007 }
3008 }
3009 21 => {
3010 if chain != Chain::Testnet && chain != Chain::Mainnet {
3011 cfg.feature_flags.consensus_fast_commit_sync = true;
3013 }
3014 if chain != Chain::Mainnet {
3015 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3020 cfg.feature_flags
3023 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3024 cfg.feature_flags
3027 .separate_gas_price_feedback_mechanism_for_randomness = true;
3028 }
3029
3030 cfg.auth_context_digest_cost_base = Some(30);
3031 cfg.auth_context_tx_commands_cost_base = Some(30);
3032 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
3033 cfg.auth_context_tx_inputs_cost_base = Some(30);
3034 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
3035 cfg.auth_context_replace_cost_base = Some(30);
3036 cfg.auth_context_replace_cost_per_byte = Some(2);
3037
3038 if chain != Chain::Testnet && chain != Chain::Mainnet {
3039 cfg.max_auth_gas = Some(250_000);
3041 }
3042 }
3043 22 => {
3044 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3049 cfg.feature_flags
3052 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3053 cfg.feature_flags
3056 .separate_gas_price_feedback_mechanism_for_randomness = true;
3057
3058 if chain != Chain::Mainnet {
3059 cfg.feature_flags.metadata_in_module_bytes = true;
3062 cfg.feature_flags.publish_package_metadata = true;
3063 cfg.feature_flags.enable_move_authentication = true;
3065 cfg.max_auth_gas = Some(250_000);
3067 cfg.transfer_receive_object_cost_base = Some(100);
3070 }
3071
3072 if chain != Chain::Mainnet {
3073 cfg.feature_flags.consensus_fast_commit_sync = true;
3075 }
3076 }
3077 23 => {
3078 cfg.feature_flags.move_native_tx_context = true;
3080 cfg.tx_context_fresh_id_cost_base = Some(52);
3081 cfg.tx_context_sender_cost_base = Some(30);
3082 cfg.tx_context_digest_cost_base = Some(30);
3083 cfg.tx_context_epoch_cost_base = Some(30);
3084 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
3085 cfg.tx_context_sponsor_cost_base = Some(30);
3086 cfg.tx_context_rgp_cost_base = Some(30);
3087 cfg.tx_context_gas_price_cost_base = Some(30);
3088 cfg.tx_context_gas_budget_cost_base = Some(30);
3089 cfg.tx_context_ids_created_cost_base = Some(30);
3090 cfg.tx_context_replace_cost_base = Some(30);
3091 }
3092 24 => {
3093 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3095
3096 if chain != Chain::Testnet && chain != Chain::Mainnet {
3097 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3099 }
3100
3101 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
3104 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
3105
3106 cfg.feature_flags.additional_borrow_checks = true;
3108 }
3109 #[allow(deprecated)]
3110 25 => {
3111 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3114 cfg.check_zklogin_id_cost_base = None;
3115 cfg.check_zklogin_issuer_cost_base = None;
3116 cfg.max_jwk_votes_per_validator_per_epoch = None;
3117 cfg.max_age_of_jwk_in_epochs = None;
3118 }
3119 26 => {
3120 }
3123 27 => {
3124 if chain != Chain::Mainnet {
3125 cfg.feature_flags.consensus_block_restrictions = true;
3128 }
3129
3130 if chain != Chain::Testnet && chain != Chain::Mainnet {
3131 cfg.feature_flags
3133 .pre_consensus_sponsor_only_move_authentication = true;
3134 }
3135 }
3136 28 => {
3137 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3142
3143 cfg.feature_flags.metadata_in_module_bytes = true;
3146 cfg.feature_flags.publish_package_metadata = true;
3147 cfg.feature_flags.enable_move_authentication = true;
3149 cfg.transfer_receive_object_cost_base = Some(100);
3152
3153 if chain != Chain::Unknown {
3154 cfg.max_auth_gas = Some(20_000);
3156 }
3157
3158 if chain != Chain::Mainnet {
3159 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3161 cfg.feature_flags
3163 .pre_consensus_sponsor_only_move_authentication = true;
3164 }
3165 }
3166 29 => {
3167 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3173
3174 cfg.feature_flags
3177 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3178
3179 cfg.feature_flags.consensus_fast_commit_sync = true;
3181 cfg.feature_flags.consensus_block_restrictions = true;
3185 }
3186 30 => {
3187 }
3195 31 => {
3196 cfg.feature_flags.validator_metadata_verify_v2 = true;
3197
3198 if chain != Chain::Mainnet && chain != Chain::Testnet {
3199 cfg.checkpoint_rate_window_size = Some(20);
3202 cfg.feature_flags
3205 .package_metadata_with_dynamic_module_metadata = true;
3206 cfg.feature_flags.consensus_starfish_speed = true;
3209 }
3210
3211 cfg.feature_flags.report_move_authentication_error = true;
3212 }
3213 32 => {
3214 cfg.min_validator_count = Some(4);
3218 cfg.max_validator_count = Some(150);
3219 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3220 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3221 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3222 cfg.validator_low_stake_grace_period = Some(7);
3223
3224 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3226 cfg.feature_flags
3228 .pre_consensus_sponsor_only_move_authentication = true;
3229
3230 if chain != Chain::Mainnet {
3231 cfg.feature_flags.consensus_starfish_speed = true;
3234 cfg.checkpoint_rate_window_size = Some(20);
3237 cfg.feature_flags
3240 .package_metadata_with_dynamic_module_metadata = true;
3241 }
3242
3243 if chain != Chain::Mainnet && chain != Chain::Testnet {
3244 cfg.feature_flags
3248 .consensus_enable_sliding_window_leader_schedule = true;
3249 cfg.feature_flags
3250 .consensus_enable_absolute_score_leader_schedule = true;
3251 cfg.feature_flags.enable_pcool_flow = true;
3255 }
3256 }
3257 33 => {
3258 cfg.checkpoint_rate_window_size = Some(20);
3261 if chain != Chain::Mainnet {
3265 cfg.feature_flags
3266 .consensus_enable_sliding_window_leader_schedule = true;
3267 cfg.feature_flags
3268 .consensus_enable_absolute_score_leader_schedule = true;
3269 }
3270 }
3271 _ => panic!("unsupported version {version:?}"),
3282 }
3283 }
3284 cfg
3285 }
3286
3287 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3293 let (
3294 max_back_edges_per_function,
3295 max_back_edges_per_module,
3296 sanity_check_with_regex_reference_safety,
3297 ) = if let Some((
3298 max_back_edges_per_function,
3299 max_back_edges_per_module,
3300 sanity_check_with_regex_reference_safety,
3301 )) = signing_limits
3302 {
3303 (
3304 Some(max_back_edges_per_function),
3305 Some(max_back_edges_per_module),
3306 Some(sanity_check_with_regex_reference_safety),
3307 )
3308 } else {
3309 (None, None, None)
3310 };
3311
3312 let additional_borrow_checks = if signing_limits.is_some() {
3313 true
3316 } else {
3317 self.additional_borrow_checks()
3318 };
3319
3320 VerifierConfig {
3321 max_loop_depth: Some(self.max_loop_depth() as usize),
3322 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3323 max_function_parameters: Some(self.max_function_parameters() as usize),
3324 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3325 max_value_stack_size: self.max_value_stack_size() as usize,
3326 max_type_nodes: Some(self.max_type_nodes() as usize),
3327 max_push_size: Some(self.max_push_size() as usize),
3328 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3329 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3330 max_function_definitions: Some(self.max_function_definitions() as usize),
3331 max_data_definitions: Some(self.max_struct_definitions() as usize),
3332 max_constant_vector_len: Some(self.max_move_vector_len()),
3333 max_back_edges_per_function,
3334 max_back_edges_per_module,
3335 max_basic_blocks_in_script: None,
3336 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
3340 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3341 additional_borrow_checks,
3342 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3343 .map(|limit| limit as u128),
3344 }
3345 }
3346
3347 pub fn apply_overrides_for_testing(
3352 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3353 ) -> OverrideGuard {
3354 CONFIG_OVERRIDE.with(|ovr| {
3355 let mut cur = ovr.borrow_mut();
3356 assert!(cur.is_none(), "config override already present");
3357 *cur = Some(Box::new(override_fn));
3358 OverrideGuard
3359 })
3360 }
3361}
3362
3363impl ProtocolConfig {
3368 pub fn set_per_object_congestion_control_mode_for_testing(
3369 &mut self,
3370 val: PerObjectCongestionControlMode,
3371 ) {
3372 self.feature_flags.per_object_congestion_control_mode = val;
3373 }
3374
3375 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3376 self.feature_flags.consensus_choice = val;
3377 }
3378
3379 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3380 self.feature_flags.consensus_network = val;
3381 }
3382
3383 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3384 self.feature_flags.passkey_auth = val
3385 }
3386
3387 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3388 self.feature_flags
3389 .disallow_new_modules_in_deps_only_packages = val;
3390 }
3391
3392 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3393 self.feature_flags.consensus_round_prober = val;
3394 }
3395
3396 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3397 self.feature_flags
3398 .consensus_distributed_vote_scoring_strategy = val;
3399 }
3400
3401 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3402 self.consensus_gc_depth = Some(val);
3403 }
3404
3405 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3406 self.feature_flags.consensus_linearize_subdag_v2 = val;
3407 }
3408
3409 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3410 self.feature_flags
3411 .consensus_round_prober_probe_accepted_rounds = val;
3412 }
3413
3414 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3415 self.feature_flags.accept_passkey_in_multisig = val;
3416 }
3417
3418 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3419 self.feature_flags.consensus_smart_ancestor_selection = val;
3420 }
3421
3422 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3423 self.feature_flags.consensus_batched_block_sync = val;
3424 }
3425
3426 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3427 self.feature_flags
3428 .congestion_control_min_free_execution_slot = val;
3429 }
3430
3431 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3432 self.feature_flags
3433 .congestion_control_gas_price_feedback_mechanism = val;
3434 }
3435
3436 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3437 self.feature_flags.select_committee_from_eligible_validators = val;
3438 }
3439
3440 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3441 self.feature_flags.track_non_committee_eligible_validators = val;
3442 }
3443
3444 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3445 self.feature_flags
3446 .select_committee_supporting_next_epoch_version = val;
3447 }
3448
3449 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3450 &mut self,
3451 val: bool,
3452 ) {
3453 self.feature_flags
3454 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3455 }
3456
3457 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3458 &mut self,
3459 val: bool,
3460 ) {
3461 self.feature_flags
3462 .consensus_commit_transactions_only_for_traversed_headers = val;
3463 }
3464
3465 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3466 &mut self,
3467 val: bool,
3468 ) {
3469 self.feature_flags
3470 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3471 }
3472
3473 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3474 &mut self,
3475 val: bool,
3476 ) {
3477 self.feature_flags
3478 .separate_gas_price_feedback_mechanism_for_randomness = val;
3479 }
3480
3481 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3482 self.feature_flags.metadata_in_module_bytes = val;
3483 }
3484
3485 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3486 self.feature_flags.publish_package_metadata = val;
3487 }
3488
3489 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3490 self.feature_flags.enable_move_authentication = val;
3491 }
3492
3493 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3494 self.feature_flags.enable_move_authentication_for_sponsor = val;
3495 }
3496
3497 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3498 self.feature_flags.consensus_fast_commit_sync = val;
3499 }
3500
3501 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3502 self.feature_flags.consensus_block_restrictions = val;
3503 }
3504
3505 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3506 self.feature_flags
3507 .pre_consensus_sponsor_only_move_authentication = val;
3508 }
3509
3510 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3511 self.feature_flags.consensus_starfish_speed = val;
3512 }
3513
3514 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3515 self.feature_flags.always_advance_dkg_to_resolution = val;
3516 }
3517
3518 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3519 self.feature_flags.enable_pcool_flow = val;
3520 }
3521
3522 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3523 self.consensus_commits_per_schedule = Some(val);
3524 }
3525
3526 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3527 self.feature_flags.deny_rule_governance = val;
3528 }
3529
3530 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
3531 self.feature_flags
3532 .package_metadata_with_dynamic_module_metadata = val;
3533 }
3534
3535 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
3536 self.feature_flags.report_move_authentication_error = val;
3537 }
3538
3539 pub fn set_leader_schedule_window_size_for_testing(&mut self, val: u32) {
3540 self.consensus_leader_schedule_window_size = Some(val);
3541 }
3542
3543 pub fn set_consensus_enable_sliding_window_leader_schedule_for_testing(&mut self, val: bool) {
3544 self.feature_flags
3545 .consensus_enable_sliding_window_leader_schedule = val;
3546 }
3547
3548 pub fn set_consensus_enable_absolute_score_leader_schedule_for_testing(&mut self, val: bool) {
3549 self.feature_flags
3550 .consensus_enable_absolute_score_leader_schedule = val;
3551 }
3552}
3553
3554type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3555
3556thread_local! {
3557 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3558}
3559
3560#[must_use]
3561pub struct OverrideGuard;
3562
3563impl Drop for OverrideGuard {
3564 fn drop(&mut self) {
3565 info!("restoring override fn");
3566 CONFIG_OVERRIDE.with(|ovr| {
3567 *ovr.borrow_mut() = None;
3568 });
3569 }
3570}
3571
3572#[derive(PartialEq, Eq)]
3576pub enum LimitThresholdCrossed {
3577 None,
3578 Soft(u128, u128),
3579 Hard(u128, u128),
3580}
3581
3582pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3585 x: T,
3586 soft_limit: U,
3587 hard_limit: V,
3588) -> LimitThresholdCrossed {
3589 let x: V = x.into();
3590 let soft_limit: V = soft_limit.into();
3591
3592 debug_assert!(soft_limit <= hard_limit);
3593
3594 if x >= hard_limit {
3597 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3598 } else if x < soft_limit {
3599 LimitThresholdCrossed::None
3600 } else {
3601 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3602 }
3603}
3604
3605#[macro_export]
3606macro_rules! check_limit {
3607 ($x:expr, $hard:expr) => {
3608 check_limit!($x, $hard, $hard)
3609 };
3610 ($x:expr, $soft:expr, $hard:expr) => {
3611 check_limit_in_range($x as u64, $soft, $hard)
3612 };
3613}
3614
3615#[macro_export]
3619macro_rules! check_limit_by_meter {
3620 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3621 let (h, metered_str) = if $is_metered {
3623 ($metered_limit, "metered")
3624 } else {
3625 ($unmetered_hard_limit, "unmetered")
3627 };
3628 use iota_protocol_config::check_limit_in_range;
3629 let result = check_limit_in_range($x as u64, $metered_limit, h);
3630 match result {
3631 LimitThresholdCrossed::None => {}
3632 LimitThresholdCrossed::Soft(_, _) => {
3633 $metric.with_label_values(&[metered_str, "soft"]).inc();
3634 }
3635 LimitThresholdCrossed::Hard(_, _) => {
3636 $metric.with_label_values(&[metered_str, "hard"]).inc();
3637 }
3638 };
3639 result
3640 }};
3641}
3642
3643#[cfg(all(test, not(msim)))]
3644mod test {
3645 use insta::assert_yaml_snapshot;
3646
3647 use super::*;
3648
3649 #[test]
3650 fn snapshot_tests() {
3651 println!("\n============================================================================");
3652 println!("! !");
3653 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3654 println!("! !");
3655 println!("============================================================================\n");
3656 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3657 let chain_str = match chain_id {
3662 Chain::Unknown => "".to_string(),
3663 _ => format!("{chain_id:?}_"),
3664 };
3665 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3666 let cur = ProtocolVersion::new(i);
3667 assert_yaml_snapshot!(
3668 format!("{}version_{}", chain_str, cur.as_u64()),
3669 ProtocolConfig::get_for_version(cur, *chain_id)
3670 );
3671 }
3672 }
3673 }
3674
3675 #[test]
3676 fn test_getters() {
3677 let prot: ProtocolConfig =
3678 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3679 assert_eq!(
3680 prot.max_arguments(),
3681 prot.max_arguments_as_option().unwrap()
3682 );
3683 }
3684
3685 #[test]
3686 fn test_setters() {
3687 let mut prot: ProtocolConfig =
3688 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3689 prot.set_max_arguments_for_testing(123);
3690 assert_eq!(prot.max_arguments(), 123);
3691
3692 prot.set_max_arguments_from_str_for_testing("321".to_string());
3693 assert_eq!(prot.max_arguments(), 321);
3694
3695 prot.disable_max_arguments_for_testing();
3696 assert_eq!(prot.max_arguments_as_option(), None);
3697
3698 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3699 assert_eq!(prot.max_arguments(), 456);
3700 }
3701
3702 #[test]
3703 #[should_panic(expected = "unsupported version")]
3704 fn max_version_test() {
3705 let _ = ProtocolConfig::get_for_version_impl(
3708 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3709 Chain::Unknown,
3710 );
3711 }
3712
3713 #[test]
3714 fn lookup_by_string_test() {
3715 let prot: ProtocolConfig =
3716 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3717 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3719
3720 assert!(
3721 prot.lookup_attr("max_arguments".to_string())
3722 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3723 );
3724
3725 assert!(
3727 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3728 .is_none()
3729 );
3730 assert!(
3731 prot.attr_map()
3732 .get("poseidon_bn254_cost_base")
3733 .unwrap()
3734 .is_none()
3735 );
3736
3737 let prot: ProtocolConfig =
3739 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3740
3741 assert!(
3742 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3743 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3744 );
3745 assert!(
3746 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3747 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3748 );
3749
3750 let prot: ProtocolConfig =
3752 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3753 assert!(
3755 prot.feature_flags
3756 .lookup_attr("some random string".to_owned())
3757 .is_none()
3758 );
3759 assert!(
3760 !prot
3761 .feature_flags
3762 .attr_map()
3763 .contains_key("some random string")
3764 );
3765
3766 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3768 assert!(
3769 prot.feature_flags
3770 .attr_map()
3771 .get("enable_poseidon")
3772 .unwrap()
3773 == &false
3774 );
3775 let prot: ProtocolConfig =
3776 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3777 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3779 assert!(
3780 prot.feature_flags
3781 .attr_map()
3782 .get("enable_poseidon")
3783 .unwrap()
3784 == &true
3785 );
3786 }
3787
3788 #[test]
3789 fn limit_range_fn_test() {
3790 let low = 100u32;
3791 let high = 10000u64;
3792
3793 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3794 assert!(matches!(
3795 check_limit!(255u16, low, high),
3796 LimitThresholdCrossed::Soft(255u128, 100)
3797 ));
3798 assert!(matches!(
3805 check_limit!(2550000u64, low, high),
3806 LimitThresholdCrossed::Hard(2550000, 10000)
3807 ));
3808
3809 assert!(matches!(
3810 check_limit!(2550000u64, high, high),
3811 LimitThresholdCrossed::Hard(2550000, 10000)
3812 ));
3813
3814 assert!(matches!(
3815 check_limit!(1u8, high),
3816 LimitThresholdCrossed::None
3817 ));
3818
3819 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3820
3821 assert!(matches!(
3822 check_limit!(2550000u64, high),
3823 LimitThresholdCrossed::Hard(2550000, 10000)
3824 ));
3825 }
3826}