Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX][CLI] verify-bytecode-meter returns module ticks #16900

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions crates/sui/src/client_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::client_ptb::ptb::PTB;
use std::{
collections::{btree_map::Entry, BTreeMap},
fmt::{Debug, Display, Formatter, Write},
fs,
path::PathBuf,
str::FromStr,
sync::Arc,
Expand All @@ -19,13 +20,14 @@ use fastcrypto::{
traits::ToFromBytes,
};

use move_binary_format::CompiledModule;
use move_core_types::language_storage::TypeTag;
use move_package::BuildConfig as MoveBuildConfig;
use prometheus::Registry;
use serde::Serialize;
use serde_json::{json, Value};
use sui_move::build::resolve_lock_file_path;
use sui_protocol_config::ProtocolConfig;
use sui_protocol_config::{Chain, ProtocolConfig, ProtocolVersion};
use sui_source_validation::{BytecodeSourceVerifier, SourceMode};

use shared_crypto::intent::Intent;
Expand Down Expand Up @@ -659,9 +661,18 @@ pub enum SuiClientCommands {
/// Run the bytecode verifier on the package
#[clap(name = "verify-bytecode-meter")]
VerifyBytecodeMeter {
/// Path to directory containing a Move package
#[clap(name = "package_path", global = true, default_value = ".")]
package_path: PathBuf,
/// Path to directory containing a Move package, (defaults to the current directory)
#[clap(name = "package", long, global = true)]
package_path: Option<PathBuf>,

/// Protocol version to use for the bytecode verifier (defaults to the latest protocol
/// version)
#[clap(name = "protocol-version", long)]
protocol_version: Option<u64>,

/// Path to specific pre-compiled module bytecode to verify (instead of an entire package)
#[clap(name = "module", long, global = true)]
module_path: Option<PathBuf>,

/// Package build options
#[clap(flatten)]
Expand Down Expand Up @@ -1056,20 +1067,49 @@ impl SuiClientCommands {
}

SuiClientCommands::VerifyBytecodeMeter {
protocol_version,
module_path,
package_path,
build_config,
} => {
let protocol_config = ProtocolConfig::get_for_max_version_UNSAFE();
let protocol_version =
protocol_version.map_or(ProtocolVersion::MAX, ProtocolVersion::new);
let protocol_config =
ProtocolConfig::get_for_version(protocol_version, Chain::Unknown);

let registry = &Registry::new();
let bytecode_verifier_metrics = Arc::new(BytecodeVerifierMetrics::new(registry));

let package = compile_package_simple(build_config, package_path)?;
let modules: Vec<_> = package.get_modules().cloned().collect();
let modules = match (module_path, package_path) {
(Some(_), Some(_)) => {
bail!("Cannot specify both a module path and a package path")
}

(Some(module_path), None) => {
let module_bytes =
fs::read(module_path).context("Failed to read module file")?;
let module = CompiledModule::deserialize_with_defaults(&module_bytes)
.context("Failed to deserialize module")?;
vec![module]
}

(None, package_path) => {
let package_path = package_path.unwrap_or_else(|| PathBuf::from("."));
let package = compile_package_simple(build_config, package_path)?;
package.get_modules().cloned().collect()
}
};

let mut verifier =
sui_execution::verifier(&protocol_config, true, &bytecode_verifier_metrics);
let overrides = VerifierOverrides::new(None, None);
println!("Running bytecode verifier for {} modules", modules.len());

println!(
"Running bytecode verifier for {} module{}",
modules.len(),
if modules.len() != 1 { "s" } else { "" },
);

let verifier_values = verifier.meter_compiled_modules_with_overrides(
&modules,
&protocol_config,
Expand Down
2 changes: 1 addition & 1 deletion sui-execution/src/latest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<'m> verifier::Verifier for Verifier<'m> {
config.max_per_mod_meter_units = config_overrides.max_per_mod_meter_units;
run_metered_move_bytecode_verifier(modules, &config, &mut self.meter, self.metrics)?;
let fun_meter_units_result = self.meter.get_usage(Scope::Function);
let mod_meter_units_result = self.meter.get_usage(Scope::Function);
let mod_meter_units_result = self.meter.get_usage(Scope::Module);
Ok(VerifierMeteredValues::new(
max_per_fun_meter_current,
max_per_mod_meter_current,
Expand Down
2 changes: 1 addition & 1 deletion sui-execution/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ impl<'m> verifier::Verifier for Verifier<'m> {
self.metrics,
)?;
let fun_meter_units_result = self.meter.get_usage(Scope::Function);
let mod_meter_units_result = self.meter.get_usage(Scope::Function);
let mod_meter_units_result = self.meter.get_usage(Scope::Module);
Ok(VerifierMeteredValues::new(
max_per_fun_meter_current,
max_per_mod_meter_current,
Expand Down
2 changes: 1 addition & 1 deletion sui-execution/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl<'m> verifier::Verifier for Verifier<'m> {
config.max_per_mod_meter_units = config_overrides.max_per_mod_meter_units;
run_metered_move_bytecode_verifier(modules, &config, &mut self.meter, self.metrics)?;
let fun_meter_units_result = self.meter.get_usage(Scope::Function);
let mod_meter_units_result = self.meter.get_usage(Scope::Function);
let mod_meter_units_result = self.meter.get_usage(Scope::Module);
Ok(VerifierMeteredValues::new(
max_per_fun_meter_current,
max_per_mod_meter_current,
Expand Down
2 changes: 1 addition & 1 deletion sui-execution/src/v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<'m> verifier::Verifier for Verifier<'m> {
config.max_per_mod_meter_units = config_overrides.max_per_mod_meter_units;
run_metered_move_bytecode_verifier(modules, &config, &mut self.meter, self.metrics)?;
let fun_meter_units_result = self.meter.get_usage(Scope::Function);
let mod_meter_units_result = self.meter.get_usage(Scope::Function);
let mod_meter_units_result = self.meter.get_usage(Scope::Module);
Ok(VerifierMeteredValues::new(
max_per_fun_meter_current,
max_per_mod_meter_current,
Expand Down
Loading