From 6590ca03721a800546c31e6c953b21fbf05826ac Mon Sep 17 00:00:00 2001 From: German Nikolishin Date: Wed, 20 Mar 2024 00:41:14 +0000 Subject: [PATCH 1/8] verify wasm --- crates/cargo-contract/src/cmd/verify.rs | 148 ++++++++++++++++++++---- 1 file changed, 128 insertions(+), 20 deletions(-) diff --git a/crates/cargo-contract/src/cmd/verify.rs b/crates/cargo-contract/src/cmd/verify.rs index f60bbdd8d..5a6de6ea6 100644 --- a/crates/cargo-contract/src/cmd/verify.rs +++ b/crates/cargo-contract/src/cmd/verify.rs @@ -25,13 +25,19 @@ use contract_build::{ BuildArtifacts, BuildInfo, BuildMode, + BuildResult, ExecuteArgs, ImageVariant, ManifestPath, + MetadataArtifacts, + MetadataResult, Verbosity, VerbosityFlags, }; -use contract_metadata::ContractMetadata; +use contract_metadata::{ + CodeHash, + ContractMetadata, +}; use std::{ fs::File, @@ -49,7 +55,11 @@ pub struct VerifyCommand { manifest_path: Option, /// The reference Wasm contract (`*.contract`) that the workspace will be checked /// against. - contract: PathBuf, + contract: Option, + /// The reference Wasm contract binary (`*.wasm`) that the workspace will be checked + /// against. + #[clap(long, conflicts_with = "contract")] + wasm: Option, /// Denotes if output should be printed to stdout. #[clap(flatten)] verbosity: VerbosityFlags, @@ -62,9 +72,88 @@ impl VerifyCommand { pub fn run(&self) -> Result { let manifest_path = ManifestPath::try_from(self.manifest_path.as_ref())?; let verbosity: Verbosity = TryFrom::<&VerbosityFlags>::try_from(&self.verbosity)?; + if let Some(path) = &self.contract { + self.verify_contract(manifest_path, verbosity, path) + } else if let Some(path) = &self.wasm { + self.verify_wasm(manifest_path, verbosity, path) + } else { + anyhow::bail!("Either --wasm or --contract must be specified") + } + } + + /// Verify `.wasm` binary. + fn verify_wasm( + &self, + manifest_path: ManifestPath, + verbosity: Verbosity, + path: &PathBuf, + ) -> Result { + // 1. Read code hash binary from the path. + let file = File::open(path) + .context(format!("Failed to open contract binary {}", path.display()))?; + + let reference_code_hash: CodeHash = serde_json::from_reader(&file).context( + format!("Failed to deserialize contract binary {}", path.display()), + )?; + + // 2. Call `cargo contract build` in the release mode. + let args = ExecuteArgs { + manifest_path: manifest_path.clone(), + verbosity, + build_mode: BuildMode::Release, + build_artifact: BuildArtifacts::All, + extra_lints: false, + ..Default::default() + }; + + let build_result = execute(args)?; + + // 4. Grab the code hash from the built contract and compare it with the reference + // one. + let built_contract_path = if let Some(m) = build_result.metadata_result { + m + } else { + // Since we're building the contract ourselves this should always be + // populated, but we'll bail out here just in case. + anyhow::bail!( + "\nThe metadata for the workspace contract does not contain a Wasm binary,\n\ + therefore we are unable to verify the contract." + .to_string() + .bright_yellow() + ) + }; + let target_bundle = &built_contract_path.dest_bundle; + + if self + .compare_code(&reference_code_hash, &verbosity, &built_contract_path) + .is_err() + { + anyhow::bail!(format!( + "\nFailed to verify the authenticity of wasm binary at {} against the workspace \n\ + found at {}.", + format!("`{}`", path.display()).bright_white(), + format!("{:?}", manifest_path.as_ref()).bright_white()).bright_red() + ); + } + Ok(VerificationResult { + is_verified: true, + image: None, + contract: target_bundle.display().to_string(), + reference_contract: path.display().to_string(), + output_json: self.output_json, + verbosity, + }) + } + + /// Verify the `.contract` bundle. + fn verify_contract( + &self, + manifest_path: ManifestPath, + verbosity: Verbosity, + path: &PathBuf, + ) -> Result { // 1. Read the given metadata, and pull out the `BuildInfo` - let path = &self.contract; let file = File::open(path) .context(format!("Failed to open contract bundle {}", path.display()))?; @@ -166,7 +255,39 @@ impl VerifyCommand { ) }; - let target_bundle = built_contract_path.dest_bundle; + let target_bundle = &built_contract_path.dest_bundle; + + if self + .compare_code(&reference_code_hash, &verbosity, &built_contract_path) + .is_err() + { + anyhow::bail!(format!( + "\nFailed to verify the authenticity of {} contract against the workspace \n\ + found at {}.", + format!("`{}`", metadata.contract.name).bright_white(), + format!("{:?}", manifest_path.as_ref()).bright_white()).bright_red() + ); + } + + Ok(VerificationResult { + is_verified: true, + image: metadata.image, + contract: target_bundle.display().to_string(), + reference_contract: path.display().to_string(), + output_json: self.output_json, + verbosity, + }) + } + + /// Compares the reference code hash with the extracted code from built contract's + /// metadata. + fn compare_code( + &self, + reference_code_hash: &CodeHash, + verbosity: &Verbosity, + built_contract_path: &MetadataArtifacts, + ) -> Result<()> { + let target_bundle = &built_contract_path.dest_bundle; let file = File::open(target_bundle.clone()).context(format!( "Failed to open contract bundle {}", @@ -180,30 +301,17 @@ impl VerifyCommand { let target_code_hash = built_contract.source.hash; - if reference_code_hash != target_code_hash { + if reference_code_hash != &target_code_hash { verbose_eprintln!( verbosity, "Expected Code Hash: '{}'\n\nGot Code Hash: `{}`", &reference_code_hash, &target_code_hash ); - - anyhow::bail!(format!( - "\nFailed to verify the authenticity of {} contract against the workspace \n\ - found at {}.", - format!("`{}`", metadata.contract.name).bright_white(), - format!("{:?}", manifest_path.as_ref()).bright_white()).bright_red() - ); + anyhow::bail!("Verification failed.") } - Ok(VerificationResult { - is_verified: true, - image: metadata.image, - contract: target_bundle.display().to_string(), - reference_contract: path.display().to_string(), - output_json: self.output_json, - verbosity, - }) + Ok(()) } } From 46ff58fa71e145684eecee36ca61ca5af82ea23e Mon Sep 17 00:00:00 2001 From: German Nikolishin Date: Wed, 20 Mar 2024 00:44:40 +0000 Subject: [PATCH 2/8] add changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d564e894..839cbface 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Verify raw Wasm in cargo contract verify - [#1551](https://github.com/paritytech/cargo-contract/pull/1551) + ## [4.0.2] ### Fixed From ff8687d60dd55a2141d2b83d7eec3102d1019363 Mon Sep 17 00:00:00 2001 From: German Nikolishin Date: Wed, 20 Mar 2024 00:47:13 +0000 Subject: [PATCH 3/8] cleanup --- crates/cargo-contract/src/cmd/verify.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/cargo-contract/src/cmd/verify.rs b/crates/cargo-contract/src/cmd/verify.rs index 5a6de6ea6..5ea2f8f4b 100644 --- a/crates/cargo-contract/src/cmd/verify.rs +++ b/crates/cargo-contract/src/cmd/verify.rs @@ -25,12 +25,10 @@ use contract_build::{ BuildArtifacts, BuildInfo, BuildMode, - BuildResult, ExecuteArgs, ImageVariant, ManifestPath, MetadataArtifacts, - MetadataResult, Verbosity, VerbosityFlags, }; From 81c2a88b3a5eb58fcf9d852b796dcdf1bf743eec Mon Sep 17 00:00:00 2001 From: German Nikolishin Date: Wed, 20 Mar 2024 01:25:26 +0000 Subject: [PATCH 4/8] load wasm directly --- crates/cargo-contract/src/cmd/verify.rs | 97 ++++++++++++------------- 1 file changed, 46 insertions(+), 51 deletions(-) diff --git a/crates/cargo-contract/src/cmd/verify.rs b/crates/cargo-contract/src/cmd/verify.rs index 5ea2f8f4b..0cd817429 100644 --- a/crates/cargo-contract/src/cmd/verify.rs +++ b/crates/cargo-contract/src/cmd/verify.rs @@ -28,7 +28,6 @@ use contract_build::{ ExecuteArgs, ImageVariant, ManifestPath, - MetadataArtifacts, Verbosity, VerbosityFlags, }; @@ -39,6 +38,10 @@ use contract_metadata::{ use std::{ fs::File, + io::{ + BufReader, + Read, + }, path::PathBuf, }; @@ -90,16 +93,21 @@ impl VerifyCommand { let file = File::open(path) .context(format!("Failed to open contract binary {}", path.display()))?; - let reference_code_hash: CodeHash = serde_json::from_reader(&file).context( - format!("Failed to deserialize contract binary {}", path.display()), - )?; + let mut reader = BufReader::new(file); + let mut buffer: [u8; 32] = [0; 32]; + reader + .read_exact(&mut buffer) + .context(format!("Failed to read contract binary {}", path.display()))?; + + let reference_code_hash = CodeHash(buffer); // 2. Call `cargo contract build` in the release mode. let args = ExecuteArgs { manifest_path: manifest_path.clone(), verbosity, + optimization_passes: Some(contract_build::OptimizationPasses::Z), build_mode: BuildMode::Release, - build_artifact: BuildArtifacts::All, + build_artifact: BuildArtifacts::CodeOnly, extra_lints: false, ..Default::default() }; @@ -108,24 +116,31 @@ impl VerifyCommand { // 4. Grab the code hash from the built contract and compare it with the reference // one. - let built_contract_path = if let Some(m) = build_result.metadata_result { + let built_wasm_path = if let Some(m) = build_result.dest_wasm { m } else { // Since we're building the contract ourselves this should always be // populated, but we'll bail out here just in case. - anyhow::bail!( - "\nThe metadata for the workspace contract does not contain a Wasm binary,\n\ + anyhow::bail!("\nThe workspace contract does not contain a Wasm binary,\n\ therefore we are unable to verify the contract." .to_string() - .bright_yellow() - ) + .bright_yellow()) }; - let target_bundle = &built_contract_path.dest_bundle; - if self - .compare_code(&reference_code_hash, &verbosity, &built_contract_path) - .is_err() - { + let file = File::open(&built_wasm_path).context(format!( + "Failed to open contract binary {}", + &built_wasm_path.display() + ))?; + + let mut reader = BufReader::new(file); + let mut buffer: [u8; 32] = [0; 32]; + reader + .read_exact(&mut buffer) + .context(format!("Failed to read contract binary {}", path.display()))?; + + let output_code_hash = CodeHash(buffer); + + if output_code_hash != reference_code_hash { anyhow::bail!(format!( "\nFailed to verify the authenticity of wasm binary at {} against the workspace \n\ found at {}.", @@ -137,7 +152,7 @@ impl VerifyCommand { Ok(VerificationResult { is_verified: true, image: None, - contract: target_bundle.display().to_string(), + contract: built_wasm_path.display().to_string(), reference_contract: path.display().to_string(), output_json: self.output_json, verbosity, @@ -255,38 +270,6 @@ impl VerifyCommand { let target_bundle = &built_contract_path.dest_bundle; - if self - .compare_code(&reference_code_hash, &verbosity, &built_contract_path) - .is_err() - { - anyhow::bail!(format!( - "\nFailed to verify the authenticity of {} contract against the workspace \n\ - found at {}.", - format!("`{}`", metadata.contract.name).bright_white(), - format!("{:?}", manifest_path.as_ref()).bright_white()).bright_red() - ); - } - - Ok(VerificationResult { - is_verified: true, - image: metadata.image, - contract: target_bundle.display().to_string(), - reference_contract: path.display().to_string(), - output_json: self.output_json, - verbosity, - }) - } - - /// Compares the reference code hash with the extracted code from built contract's - /// metadata. - fn compare_code( - &self, - reference_code_hash: &CodeHash, - verbosity: &Verbosity, - built_contract_path: &MetadataArtifacts, - ) -> Result<()> { - let target_bundle = &built_contract_path.dest_bundle; - let file = File::open(target_bundle.clone()).context(format!( "Failed to open contract bundle {}", target_bundle.display() @@ -299,17 +282,29 @@ impl VerifyCommand { let target_code_hash = built_contract.source.hash; - if reference_code_hash != &target_code_hash { + if reference_code_hash != target_code_hash { verbose_eprintln!( verbosity, "Expected Code Hash: '{}'\n\nGot Code Hash: `{}`", &reference_code_hash, &target_code_hash ); - anyhow::bail!("Verification failed.") + anyhow::bail!(format!( + "\nFailed to verify the authenticity of {} contract against the workspace \n\ + found at {}.", + format!("`{}`", metadata.contract.name).bright_white(), + format!("{:?}", manifest_path.as_ref()).bright_white()).bright_red() + ); } - Ok(()) + Ok(VerificationResult { + is_verified: true, + image: metadata.image, + contract: target_bundle.display().to_string(), + reference_contract: path.display().to_string(), + output_json: self.output_json, + verbosity, + }) } } From 2fe1023cc43ad4082b113594e0af04ba4876d98a Mon Sep 17 00:00:00 2001 From: German Nikolishin Date: Wed, 20 Mar 2024 21:17:19 +0000 Subject: [PATCH 5/8] correctly compare wasm binaries + tests --- crates/cargo-contract/src/cmd/verify.rs | 27 ++++++----- crates/cargo-contract/tests/verify.rs | 61 +++++++++++++++++++------ 2 files changed, 61 insertions(+), 27 deletions(-) diff --git a/crates/cargo-contract/src/cmd/verify.rs b/crates/cargo-contract/src/cmd/verify.rs index 0cd817429..6c397c321 100644 --- a/crates/cargo-contract/src/cmd/verify.rs +++ b/crates/cargo-contract/src/cmd/verify.rs @@ -20,6 +20,7 @@ use anyhow::{ }; use colored::Colorize; use contract_build::{ + code_hash, execute, verbose_eprintln, BuildArtifacts, @@ -31,10 +32,7 @@ use contract_build::{ Verbosity, VerbosityFlags, }; -use contract_metadata::{ - CodeHash, - ContractMetadata, -}; +use contract_metadata::ContractMetadata; use std::{ fs::File, @@ -56,6 +54,7 @@ pub struct VerifyCommand { manifest_path: Option, /// The reference Wasm contract (`*.contract`) that the workspace will be checked /// against. + #[clap(long)] contract: Option, /// The reference Wasm contract binary (`*.wasm`) that the workspace will be checked /// against. @@ -93,13 +92,13 @@ impl VerifyCommand { let file = File::open(path) .context(format!("Failed to open contract binary {}", path.display()))?; - let mut reader = BufReader::new(file); - let mut buffer: [u8; 32] = [0; 32]; - reader - .read_exact(&mut buffer) + let mut ref_reader = BufReader::new(file); + let mut ref_buffer = Vec::new(); + ref_reader + .read_to_end(&mut ref_buffer) .context(format!("Failed to read contract binary {}", path.display()))?; - let reference_code_hash = CodeHash(buffer); + let reference_code_hash = code_hash(&ref_buffer); // 2. Call `cargo contract build` in the release mode. let args = ExecuteArgs { @@ -132,13 +131,13 @@ impl VerifyCommand { &built_wasm_path.display() ))?; - let mut reader = BufReader::new(file); - let mut buffer: [u8; 32] = [0; 32]; - reader - .read_exact(&mut buffer) + let mut target_reader = BufReader::new(file); + let mut target_buffer = Vec::new(); + target_reader + .read_to_end(&mut target_buffer) .context(format!("Failed to read contract binary {}", path.display()))?; - let output_code_hash = CodeHash(buffer); + let output_code_hash = code_hash(&target_buffer); if output_code_hash != reference_code_hash { anyhow::bail!(format!( diff --git a/crates/cargo-contract/tests/verify.rs b/crates/cargo-contract/tests/verify.rs index 52b096e52..f34f4db6b 100644 --- a/crates/cargo-contract/tests/verify.rs +++ b/crates/cargo-contract/tests/verify.rs @@ -23,8 +23,9 @@ fn cargo_contract>(path: P) -> assert_cmd::Command { cmd } -/// Compile the reference contract and return a byte array of its bundle. -fn compile_reference_contract() -> Vec { +/// Compile the reference contract and return a byte array of its bundle and raw wasm +/// binary. +fn compile_reference_contract() -> (Vec, Vec) { let contract = r#" #![cfg_attr(not(feature = "std"), no_std, no_main)] @@ -48,7 +49,7 @@ fn compile_reference_contract() -> Vec { #[ink(message)] pub fn inc(&mut self, by: i32) { - self.value.saturating_add(by); + self.value = self.value.saturating_add(by); } #[ink(message, selector = 0xCACACACA)] @@ -82,9 +83,14 @@ fn compile_reference_contract() -> Vec { .success(); let bundle_path = project_dir.join("target/ink/incrementer.contract"); + let bundle = std::fs::read(bundle_path) + .expect("Failed to read the content of the contract bundle!"); - std::fs::read(bundle_path) - .expect("Failed to read the content of the contract bundle!") + let wasm_path = project_dir.join("target/ink/incrementer.wasm"); + let wasm = std::fs::read(wasm_path) + .expect("Failed to read the content of the contract binary!"); + + (bundle, wasm) } #[test] @@ -113,7 +119,7 @@ fn verify_equivalent_contracts() { #[ink(message)] pub fn inc(&mut self, by: i32) { - self.value.saturating_add(by); + self.value = self.value.saturating_add(by); } #[ink(message, selector = 0xCACACACA)] @@ -139,11 +145,14 @@ fn verify_equivalent_contracts() { let lib = project_dir.join("lib.rs"); std::fs::write(lib, contract).expect("Failed to write contract lib.rs"); - // Compile reference contract and write bundle in the directory. - let reference_contents = compile_reference_contract(); + // Compile reference contract and write bundle and wasm in the directory. + let (ref_bundle, ref_wasm) = compile_reference_contract(); let bundle = project_dir.join("reference.contract"); - std::fs::write(bundle, reference_contents) + std::fs::write(bundle, ref_bundle) .expect("Failed to write bundle contract to the current dir!"); + let wasm = project_dir.join("reference.wasm"); + std::fs::write(wasm, ref_wasm) + .expect("Failed to write wasm binary to the current dir!"); // when let output: &str = r#""is_verified": true"#; @@ -151,11 +160,21 @@ fn verify_equivalent_contracts() { // then cargo_contract(&project_dir) .arg("verify") + .arg("--contract") .arg("reference.contract") .arg("--output-json") .assert() .success() .stdout(predicates::str::contains(output)); + // and + cargo_contract(&project_dir) + .arg("verify") + .arg("--wasm") + .arg("reference.wasm") + .arg("--output-json") + .assert() + .success() + .stdout(predicates::str::contains(output)); } #[test] @@ -184,7 +203,7 @@ fn verify_different_contracts() { #[ink(message)] pub fn inc(&mut self, by: i32) { - self.value.saturating_add(by); + self.value = self.value.saturating_add(by); } #[ink(message, selector = 0xCBCBCBCB)] @@ -214,11 +233,14 @@ fn verify_different_contracts() { tracing::debug!("Building contract in {}", project_dir.to_string_lossy()); cargo_contract(&project_dir).arg("build").assert().success(); - // Compile reference contract and write bundle in the directory. - let reference_contents = compile_reference_contract(); + // Compile reference contract and write bundle and wasm in the directory. + let (ref_bundle, ref_wasm) = compile_reference_contract(); let bundle = project_dir.join("reference.contract"); - std::fs::write(bundle, reference_contents) + std::fs::write(bundle, ref_bundle) .expect("Failed to write bundle contract to the current dir!"); + let wasm = project_dir.join("reference.wasm"); + std::fs::write(wasm, ref_wasm) + .expect("Failed to write wasm binary to the current dir!"); // when let output: &str = r#"Failed to verify the authenticity of `incrementer`"#; @@ -226,9 +248,22 @@ fn verify_different_contracts() { // then cargo_contract(&project_dir) .arg("verify") + .arg("--contract") .arg("reference.contract") .arg("--output-json") .assert() .failure() .stderr(predicates::str::contains(output)); + // and + + let output: &str = + r#"Failed to verify the authenticity of wasm binary at `reference.wasm`"#; + cargo_contract(&project_dir) + .arg("verify") + .arg("--wasm") + .arg("reference.wasm") + .arg("--output-json") + .assert() + .failure() + .stderr(predicates::str::contains(output)); } From f3d5fc0693bf34e3dd63e1b674c087219e0950c5 Mon Sep 17 00:00:00 2001 From: Gherman Date: Thu, 21 Mar 2024 16:18:51 +0000 Subject: [PATCH 6/8] Apply suggestions from code review Co-authored-by: Andrew Jones --- crates/cargo-contract/src/cmd/verify.rs | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/crates/cargo-contract/src/cmd/verify.rs b/crates/cargo-contract/src/cmd/verify.rs index 6c397c321..70855a2eb 100644 --- a/crates/cargo-contract/src/cmd/verify.rs +++ b/crates/cargo-contract/src/cmd/verify.rs @@ -89,13 +89,7 @@ impl VerifyCommand { path: &PathBuf, ) -> Result { // 1. Read code hash binary from the path. - let file = File::open(path) - .context(format!("Failed to open contract binary {}", path.display()))?; - - let mut ref_reader = BufReader::new(file); - let mut ref_buffer = Vec::new(); - ref_reader - .read_to_end(&mut ref_buffer) + let ref_buffer = std::fs::read(path) .context(format!("Failed to read contract binary {}", path.display()))?; let reference_code_hash = code_hash(&ref_buffer); @@ -126,16 +120,8 @@ impl VerifyCommand { .bright_yellow()) }; - let file = File::open(&built_wasm_path).context(format!( - "Failed to open contract binary {}", - &built_wasm_path.display() - ))?; - - let mut target_reader = BufReader::new(file); - let mut target_buffer = Vec::new(); - target_reader - .read_to_end(&mut target_buffer) - .context(format!("Failed to read contract binary {}", path.display()))?; + let target_buffer = std::fs::read(&built_wasm_path) + .context(format!("Failed to read contract binary {}", built_wasm_path.display()))?; let output_code_hash = code_hash(&target_buffer); From 7ea75d9fe5f2794f741cf6e229384652eaa9981c Mon Sep 17 00:00:00 2001 From: German Nikolishin Date: Thu, 21 Mar 2024 16:57:09 +0000 Subject: [PATCH 7/8] refactor --- crates/cargo-contract/src/cmd/verify.rs | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/crates/cargo-contract/src/cmd/verify.rs b/crates/cargo-contract/src/cmd/verify.rs index 70855a2eb..2a803e60c 100644 --- a/crates/cargo-contract/src/cmd/verify.rs +++ b/crates/cargo-contract/src/cmd/verify.rs @@ -32,14 +32,13 @@ use contract_build::{ Verbosity, VerbosityFlags, }; -use contract_metadata::ContractMetadata; +use contract_metadata::{ + CodeHash, + ContractMetadata, +}; use std::{ fs::File, - io::{ - BufReader, - Read, - }, path::PathBuf, }; @@ -89,10 +88,10 @@ impl VerifyCommand { path: &PathBuf, ) -> Result { // 1. Read code hash binary from the path. - let ref_buffer = std::fs::read(path) + let ref_buffer = std::fs::read(path) .context(format!("Failed to read contract binary {}", path.display()))?; - let reference_code_hash = code_hash(&ref_buffer); + let reference_code_hash = CodeHash(code_hash(&ref_buffer)); // 2. Call `cargo contract build` in the release mode. let args = ExecuteArgs { @@ -120,17 +119,21 @@ impl VerifyCommand { .bright_yellow()) }; - let target_buffer = std::fs::read(&built_wasm_path) - .context(format!("Failed to read contract binary {}", built_wasm_path.display()))?; + let target_buffer = std::fs::read(&built_wasm_path).context(format!( + "Failed to read contract binary {}", + built_wasm_path.display() + ))?; - let output_code_hash = code_hash(&target_buffer); + let output_code_hash = CodeHash(code_hash(&target_buffer)); if output_code_hash != reference_code_hash { anyhow::bail!(format!( "\nFailed to verify the authenticity of wasm binary at {} against the workspace \n\ - found at {}.", + found at {}.\n Expected {}, found {}", + format!("`{}`", built_wasm_path.display()).bright_white(), format!("`{}`", path.display()).bright_white(), - format!("{:?}", manifest_path.as_ref()).bright_white()).bright_red() + format!("{}", reference_code_hash).bright_white(), + format!("{}", output_code_hash).bright_white()) ); } From 3a234cb1fba17451ba4706d27034370524117f7d Mon Sep 17 00:00:00 2001 From: German Nikolishin Date: Thu, 21 Mar 2024 17:17:53 +0000 Subject: [PATCH 8/8] fix error stderr --- crates/cargo-contract/src/cmd/verify.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cargo-contract/src/cmd/verify.rs b/crates/cargo-contract/src/cmd/verify.rs index 2a803e60c..88c379071 100644 --- a/crates/cargo-contract/src/cmd/verify.rs +++ b/crates/cargo-contract/src/cmd/verify.rs @@ -130,8 +130,8 @@ impl VerifyCommand { anyhow::bail!(format!( "\nFailed to verify the authenticity of wasm binary at {} against the workspace \n\ found at {}.\n Expected {}, found {}", - format!("`{}`", built_wasm_path.display()).bright_white(), format!("`{}`", path.display()).bright_white(), + format!("`{}`", built_wasm_path.display()).bright_white(), format!("{}", reference_code_hash).bright_white(), format!("{}", output_code_hash).bright_white()) );