Skip to main content

sui_execution/
verifier.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use move_binary_format::CompiledModule;
5use move_bytecode_verifier_meter::Meter;
6use move_vm_config::verifier::MeterConfig;
7use sui_protocol_config::ProtocolConfig;
8use sui_types::error::SuiResult;
9
10pub trait Verifier {
11    /// Create a new bytecode verifier meter.
12    fn meter(&self, config: MeterConfig) -> Box<dyn Meter>;
13
14    /// Specifies whether or not deprecate_global_storage_ops_during_deserialization should
15    /// be overridden for the `BinaryConfig`
16    fn override_deprecate_global_storage_ops_during_deserialization(&self) -> Option<bool>;
17
18    /// Run the bytecode verifier with a meter limit
19    ///
20    /// This function only fails if the verification does not complete within the limit.  If the
21    /// modules fail to verify but verification completes within the meter limit, the function
22    /// succeeds.
23    fn meter_compiled_modules(
24        &mut self,
25        protocol_config: &ProtocolConfig,
26        modules: &[CompiledModule],
27        meter: &mut dyn Meter,
28    ) -> SuiResult<()>;
29
30    fn meter_module_bytes(
31        &mut self,
32        protocol_config: &ProtocolConfig,
33        module_bytes: &[Vec<u8>],
34        meter: &mut dyn Meter,
35    ) -> SuiResult<()> {
36        let binary_config = protocol_config
37            .binary_config(self.override_deprecate_global_storage_ops_during_deserialization());
38        let Ok(modules) = module_bytes
39            .iter()
40            .map(|b| CompiledModule::deserialize_with_config(b, &binary_config))
41            .collect::<Result<Vec<_>, _>>()
42        else {
43            // Although we failed, we don't care since it wasn't because of a timeout.
44            return Ok(());
45        };
46
47        for module in &modules {
48            for identifier in module.identifiers() {
49                if identifier.as_str() == "<SELF>" {
50                    return Err(sui_types::error::UserInputError::InvalidIdentifier {
51                        error: format!("invalid identifier: {}", identifier),
52                    }
53                    .into());
54                }
55            }
56        }
57
58        self.meter_compiled_modules(protocol_config, &modules, meter)
59    }
60}