Skip to content

Commit 96113df

Browse files
committed
Migrate BLAKE3 to BLAKE2 for easier cross-compilation
1 parent 234e93e commit 96113df

File tree

5 files changed

+19
-39
lines changed

5 files changed

+19
-39
lines changed

Cargo.lock

Lines changed: 7 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/vm-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ license = "Apache-2.0"
1010
proc-macro = true
1111

1212
[dependencies]
13-
blake3 = "1.5"
13+
blake2 = "0.10.6"
1414
proc-macro2 = "1.0.86"
1515
quote = "1.0.37"
1616
syn = { version = "2.0.77", features = ["extra-traits", "full"] }

packages/vm-derive/src/hash_function.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::hash::{Hash, Hasher};
22

3+
use blake2::{Blake2b512, Digest};
34
use proc_macro2::TokenStream;
45
use quote::{quote, ToTokens};
56
use syn::{punctuated::Punctuated, Token};
@@ -36,18 +37,18 @@ impl syn::parse::Parse for Options {
3637
}
3738

3839
struct Blake3Hasher {
39-
hasher: blake3::Hasher,
40+
hasher: Blake2b512,
4041
}
4142

4243
impl Blake3Hasher {
4344
fn new() -> Self {
4445
Self {
45-
hasher: blake3::Hasher::new(),
46+
hasher: Blake2b512::new(),
4647
}
4748
}
4849

49-
fn consume(self) -> blake3::Hash {
50-
self.hasher.finalize()
50+
fn consume(self) -> [u8; 64] {
51+
self.hasher.finalize().into()
5152
}
5253
}
5354

@@ -72,7 +73,7 @@ pub fn hash_function_impl(attr: TokenStream, input: TokenStream) -> TokenStream
7273
let hash = hasher.consume();
7374

7475
let hash_variable_name = &options.const_name;
75-
let hash_bytes = hash.as_bytes();
76+
let hash_bytes = hash.as_slice();
7677

7778
quote! {
7879
pub const #hash_variable_name: &[u8] = &[#(#hash_bytes),*];

packages/vm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bytes = "1.4.0" # need a higher version than the one required by Wasmer for
4444
clru = "0.6.1"
4545
crc32fast = "1.3.2"
4646
bech32 = "0.11.0"
47-
blake3 = "1.5"
47+
blake2 = "0.10.6"
4848
# Uses the path when built locally; uses the given version from crates.io when published
4949
cosmwasm-core = { version = "2.2.0-rc.1", path = "../core" }
5050
cosmwasm-std = { version = "2.2.0-rc.1", path = "../std", default-features = false, features = [

packages/vm/src/modules/file_system_cache.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use blake2::{digest::consts::U5, Blake2b, Digest};
12
use std::fs;
23
use std::hash::Hash;
34
use std::io;
@@ -75,7 +76,7 @@ const MODULE_SERIALIZATION_VERSION: &str = "v20";
7576
fn raw_module_version_discriminator() -> String {
7677
let hashes = [COST_FUNCTION_HASH];
7778

78-
let mut hasher = blake3::Hasher::new();
79+
let mut hasher = Blake2b::<U5>::new();
7980

8081
hasher.update(MODULE_SERIALIZATION_VERSION.as_bytes());
8182
hasher.update(wasmer::VERSION.as_bytes());
@@ -84,7 +85,7 @@ fn raw_module_version_discriminator() -> String {
8485
hasher.update(hash);
8586
}
8687

87-
hasher.finalize().to_hex().to_string()
88+
hex::encode(hasher.finalize())
8889
}
8990

9091
/// This version __MUST__ change whenever the module system changes in a way
@@ -481,7 +482,7 @@ mod tests {
481482
let version = raw_module_version_discriminator();
482483
assert_eq!(
483484
version,
484-
"b2a230627e6fd9c14c45aabcf781b58d873dd251fcb004d30e081c8407cad5af"
485+
"5b35f8ce52"
485486
);
486487
}
487488
}

0 commit comments

Comments
 (0)