-
Notifications
You must be signed in to change notification settings - Fork 125
Add verify command
#696
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
Add verify command
#696
Changes from 1 commit
51117cc
13d29dc
85ccd7d
7de595c
e67d108
b90f126
a350f4c
e87c51a
4317f55
fed9c3f
b743987
f6770de
2f3ca03
e2c5675
963387c
e7b9577
a64b631
d6db73f
80233c4
98cc7fb
b2d10c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,11 +58,10 @@ impl VerifyCommand { | |
| let build_info = metadata.source.build_info.as_ref().unwrap(); | ||
| let build_info: BuildInfo = | ||
| serde_json::from_value(build_info.clone().into()).unwrap(); | ||
| dbg!(&build_info); | ||
|
|
||
| // 2. Call `cmd::Build` with the given `BuildInfo` | ||
| let args = ExecuteArgs { | ||
| manifest_path, | ||
| manifest_path: manifest_path.clone(), | ||
| verbosity: Default::default(), | ||
| build_mode: build_info.build_mode, | ||
| network: Default::default(), | ||
|
|
@@ -74,9 +73,41 @@ impl VerifyCommand { | |
| output_type: Default::default(), | ||
| }; | ||
|
|
||
| let _build_result = execute(args)?; | ||
| let build_result = execute(args)?; | ||
|
|
||
| // 3. Read output file, compare with given contract_wasm | ||
| todo!() | ||
| let reference_wasm = metadata.source.wasm.unwrap().to_string(); | ||
|
|
||
| let built_wasm_path = build_result.dest_wasm.unwrap(); | ||
| let fs_wasm = std::fs::read(built_wasm_path)?; | ||
| let built_wasm = build_byte_str(&fs_wasm); | ||
|
|
||
| if reference_wasm != built_wasm { | ||
| log::debug!( | ||
| "Expected Wasm Binary '{}'\n\nGot Wasm Binary `{}`", | ||
| &reference_wasm, | ||
| &built_wasm | ||
| ); | ||
| anyhow::bail!( | ||
| "Failed to verify the authenticity of `{}` contract againt the workspace found at {:?}.", | ||
| metadata.contract.name, | ||
| manifest_path.as_ref(), | ||
| ); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be super useful to print out the It's useful to know whether they are the same or different for figuring out why verification failed. And while we are at it, any other properties we have available in |
||
| } | ||
|
|
||
| log::info!("Succesfully verified `{}`!", &metadata.contract.name); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| fn build_byte_str(bytes: &[u8]) -> String { | ||
| use std::fmt::Write; | ||
|
|
||
| let mut str = String::new(); | ||
| write!(str, "0x").expect("failed writing to string"); | ||
| for byte in bytes { | ||
| write!(str, "{:02x}", byte).expect("failed writing to string"); | ||
| } | ||
| str | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should also compare the contract ABI metadata itself? They should be identical too, and if not it might give clues as to what (if anything) is different.