sui_config/
verifier_signing_config.rs

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