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

[r2r] Add checksum verification of Zcash params files #1549

Merged
merged 16 commits into from
Nov 21, 2022

Conversation

laruh
Copy link
Member

@laruh laruh commented Nov 17, 2022

related to ARRR integration. #927

Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! It's the first review iteration.

mm2src/coins/z_coin.rs Outdated Show resolved Hide resolved
mm2src/coins/z_coin.rs Outdated Show resolved Hide resolved
mm2src/coins/z_coin.rs Outdated Show resolved Hide resolved
mm2src/coins/z_coin.rs Outdated Show resolved Hide resolved
mm2src/coins/z_coin/z_coin_errors.rs Outdated Show resolved Hide resolved
@laruh laruh changed the title [r2r] Add checksum verification of Zcash params files [wip] Add checksum verification of Zcash params files Nov 18, 2022
@laruh laruh changed the title [wip] Add checksum verification of Zcash params files [r2r] Add checksum verification of Zcash params files Nov 18, 2022
artemii235
artemii235 previously approved these changes Nov 18, 2022
Copy link
Member

@artemii235 artemii235 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@artemii235
Copy link
Member

@ozkanonur Could you take a look too, please?

Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, just notes :)

Comment on lines 743 to 761
/// open file and calculate its sha256 digest as lowercase hex string
fn sha256_digest(path: &PathBuf) -> Result<String, ZCoinBuildError> {
let input = File::open(path)?;
let mut reader = BufReader::new(input);

let digest = {
let mut hasher = Sha256::new();
let mut buffer = [0; 1024];
loop {
let count = reader.read(&mut buffer)?;
if count == 0 {
break;
}
hasher.update(&buffer[..count]);
}
format!("{:x}", hasher.finalize())
};
Ok(digest)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks like a general purpose function that could be placed in common module for reusability.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 770 to 780
let (spend_path, output_path) = if params_dir.exists() {
(
params_dir.join(SAPLING_SPEND_NAME),
params_dir.join(SAPLING_OUTPUT_NAME),
)
} else {
return Err(ZCoinBuildError::ZCashParamsNotFound);
};
if !(spend_path.exists() && output_path.exists()) {
return Err(ZCoinBuildError::ZCashParamsNotFound);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, the following code looks more readable because it includes less blocks.

if !params_dir.exists() {
    return Err(ZCoinBuildError::ZCashParamsNotFound);
}

let spend_path = params_dir.join(SAPLING_SPEND_NAME);
let output_path = params_dir.join(SAPLING_OUTPUT_NAME);

if !(spend_path.exists() && output_path.exists()) {
    return Err(ZCoinBuildError::ZCashParamsNotFound);
}

Just sharing my thought, maybe it's just me :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, it looks better.
Done

@laruh laruh changed the title [r2r] Add checksum verification of Zcash params files [wip] Add checksum verification of Zcash params files Nov 21, 2022
@laruh laruh changed the title [wip] Add checksum verification of Zcash params files [r2r] Add checksum verification of Zcash params files Nov 21, 2022
Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2nd review iteraton

@@ -117,6 +117,8 @@ pub mod wio;

#[cfg(target_arch = "wasm32")] pub use wasm::*;

#[cfg(target_arch = "wasm32")] use std::path::PathBuf;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be imported without any condition. Atm it's imported twice for native and wasm mode.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just had this error and recomendation to import std::path::PathBuf. Sorry, what do you mean by condition?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[cfg(target_arch = "wasm32")] this is compile-time check which provides conditional compilation.

We have PathBuf imported as

#[cfg(target_arch = "wasm32")] use std::path::PathBuf;

and

cfg_native!{ // checks if target isn't wasm
    use std::path::PathBuf;
}

Because we are using it for both targets, we can import it as it is without any compile-time condition.

Copy link
Member Author

@laruh laruh Nov 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, got it, thanks! It is imported without condition now.
Done.

Copy link
Member

@onur-ozkan onur-ozkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me :)

@artemii235 artemii235 merged commit b2f1eb1 into dev Nov 21, 2022
@artemii235 artemii235 deleted the add_checksum_verification_of_Zcash_params branch November 21, 2022 14:14
@laruh laruh mentioned this pull request Feb 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants