iota_config/
verifier_signing_config.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2025 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use move_vm_config::verifier::MeterConfig;
6use serde::{Deserialize, Serialize};
7
8// Default values for verifier signing config.
9pub const DEFAULT_MAX_PER_FUN_METER_UNITS: usize = 2_200_000;
10pub const DEFAULT_MAX_PER_MOD_METER_UNITS: usize = 2_200_000;
11pub const DEFAULT_MAX_PER_PKG_METER_UNITS: usize = 2_200_000;
12
13pub const DEFAULT_MAX_BACK_EDGES_PER_FUNCTION: usize = 10_000;
14pub const DEFAULT_MAX_BACK_EDGES_PER_MODULE: usize = 10_000;
15
16pub const DEFAULT_SANITY_CHECK_WITH_REGEX_REFERENCE_SAFETY_UNITS: usize = 2_200_000;
17
18/// This holds limits that are only set and used by the verifier during signing
19/// _only_. There are additional limits in the `MeterConfig` and
20/// `VerifierConfig` that are used during both signing and execution, however
21/// those limits cannot be set here and must be protocol versioned.
22#[derive(Clone, Debug, Default, Deserialize, Serialize)]
23#[serde(rename_all = "kebab-case")]
24pub struct VerifierSigningConfig {
25    #[serde(default)]
26    max_per_fun_meter_units: Option<usize>,
27    #[serde(default)]
28    max_per_mod_meter_units: Option<usize>,
29    #[serde(default)]
30    max_per_pkg_meter_units: Option<usize>,
31
32    #[serde(default)]
33    max_back_edges_per_function: Option<usize>,
34    #[serde(default)]
35    max_back_edges_per_module: Option<usize>,
36
37    #[serde(default)]
38    pub sanity_check_with_regex_reference_safety: Option<usize>,
39}
40
41impl VerifierSigningConfig {
42    pub fn max_per_fun_meter_units(&self) -> usize {
43        self.max_per_fun_meter_units
44            .unwrap_or(DEFAULT_MAX_PER_FUN_METER_UNITS)
45    }
46
47    pub fn max_per_mod_meter_units(&self) -> usize {
48        self.max_per_mod_meter_units
49            .unwrap_or(DEFAULT_MAX_PER_MOD_METER_UNITS)
50    }
51
52    pub fn max_per_pkg_meter_units(&self) -> usize {
53        self.max_per_pkg_meter_units
54            .unwrap_or(DEFAULT_MAX_PER_PKG_METER_UNITS)
55    }
56
57    pub fn max_back_edges_per_function(&self) -> usize {
58        self.max_back_edges_per_function
59            .unwrap_or(DEFAULT_MAX_BACK_EDGES_PER_FUNCTION)
60    }
61
62    pub fn max_back_edges_per_module(&self) -> usize {
63        self.max_back_edges_per_module
64            .unwrap_or(DEFAULT_MAX_BACK_EDGES_PER_MODULE)
65    }
66
67    pub fn sanity_check_with_regex_reference_safety(&self) -> usize {
68        self.sanity_check_with_regex_reference_safety
69            .unwrap_or(DEFAULT_SANITY_CHECK_WITH_REGEX_REFERENCE_SAFETY_UNITS)
70    }
71
72    /// Return sign-time only limit for back edges for the verifier.
73    pub fn limits_for_signing(&self) -> (usize, usize, usize) {
74        (
75            self.max_back_edges_per_function(),
76            self.max_back_edges_per_module(),
77            self.sanity_check_with_regex_reference_safety(),
78        )
79    }
80
81    /// MeterConfig for metering packages during signing. It is NOT stable
82    /// between binaries and cannot used during execution.
83    pub fn meter_config_for_signing(&self) -> MeterConfig {
84        MeterConfig {
85            max_per_fun_meter_units: Some(self.max_per_fun_meter_units() as u128),
86            max_per_mod_meter_units: Some(self.max_per_mod_meter_units() as u128),
87            max_per_pkg_meter_units: Some(self.max_per_pkg_meter_units() as u128),
88        }
89    }
90}