iota_execution/
verifier.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use iota_protocol_config::ProtocolConfig;
6use iota_types::{error::IotaResult, execution_config_utils::to_binary_config};
7use move_binary_format::CompiledModule;
8use move_bytecode_verifier_meter::Meter;
9use move_vm_config::verifier::MeterConfig;
10
11pub trait Verifier {
12    /// Create a new bytecode verifier meter.
13    fn meter(&self, config: MeterConfig) -> Box<dyn Meter>;
14
15    /// Run the bytecode verifier with a meter limit
16    ///
17    /// This function only fails if the verification does not complete within
18    /// the limit.  If the modules fail to verify but verification completes
19    /// within the meter limit, the function succeeds.
20    fn meter_compiled_modules(
21        &mut self,
22        protocol_config: &ProtocolConfig,
23        modules: &[CompiledModule],
24        meter: &mut dyn Meter,
25    ) -> IotaResult<()>;
26
27    fn meter_module_bytes(
28        &mut self,
29        protocol_config: &ProtocolConfig,
30        module_bytes: &[Vec<u8>],
31        meter: &mut dyn Meter,
32    ) -> IotaResult<()> {
33        let binary_config = to_binary_config(protocol_config);
34        let Ok(modules) = module_bytes
35            .iter()
36            .map(|b| CompiledModule::deserialize_with_config(b, &binary_config))
37            .collect::<Result<Vec<_>, _>>()
38        else {
39            // Although we failed, we don't care since it wasn't because of a timeout.
40            return Ok(());
41        };
42
43        self.meter_compiled_modules(protocol_config, &modules, meter)
44    }
45}