From 96113dfd96753ac268c03106536ffaa533268bef Mon Sep 17 00:00:00 2001 From: Aumetra Weisman Date: Mon, 7 Oct 2024 13:14:30 +0200 Subject: [PATCH] Migrate BLAKE3 to BLAKE2 for easier cross-compilation --- Cargo.lock | 36 ++++---------------- packages/vm-derive/Cargo.toml | 2 +- packages/vm-derive/src/hash_function.rs | 11 +++--- packages/vm/Cargo.toml | 2 +- packages/vm/src/modules/file_system_cache.rs | 7 ++-- 5 files changed, 19 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9e1b53f1d..bc4d60b3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" @@ -247,18 +247,6 @@ dependencies = [ "rayon", ] -[[package]] -name = "arrayref" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" - -[[package]] -name = "arrayvec" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" - [[package]] name = "assert_cmd" version = "2.0.14" @@ -354,16 +342,12 @@ dependencies = [ ] [[package]] -name = "blake3" -version = "1.5.0" +name = "blake2" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0231f06152bf547e9c2b5194f247cd97aacf6dcd8b15d8e5ec0663f64580da87" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "arrayref", - "arrayvec", - "cc", - "cfg-if", - "constant_time_eq", + "digest", ] [[package]] @@ -544,12 +528,6 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" -[[package]] -name = "constant_time_eq" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" - [[package]] name = "convert_case" version = "0.6.0" @@ -688,7 +666,7 @@ name = "cosmwasm-vm" version = "2.2.0-rc.1" dependencies = [ "bech32", - "blake3", + "blake2", "bytes", "clap", "clru", @@ -727,7 +705,7 @@ dependencies = [ name = "cosmwasm-vm-derive" version = "2.2.0-rc.1" dependencies = [ - "blake3", + "blake2", "proc-macro2", "quote", "syn 2.0.77", diff --git a/packages/vm-derive/Cargo.toml b/packages/vm-derive/Cargo.toml index ea24a1b0d..6eb74280e 100644 --- a/packages/vm-derive/Cargo.toml +++ b/packages/vm-derive/Cargo.toml @@ -10,7 +10,7 @@ license = "Apache-2.0" proc-macro = true [dependencies] -blake3 = "1.5" +blake2 = "0.10.6" proc-macro2 = "1.0.86" quote = "1.0.37" syn = { version = "2.0.77", features = ["extra-traits", "full"] } diff --git a/packages/vm-derive/src/hash_function.rs b/packages/vm-derive/src/hash_function.rs index 44faf770a..3d792dcbf 100644 --- a/packages/vm-derive/src/hash_function.rs +++ b/packages/vm-derive/src/hash_function.rs @@ -1,5 +1,6 @@ use std::hash::{Hash, Hasher}; +use blake2::{Blake2b512, Digest}; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; use syn::{punctuated::Punctuated, Token}; @@ -36,18 +37,18 @@ impl syn::parse::Parse for Options { } struct Blake3Hasher { - hasher: blake3::Hasher, + hasher: Blake2b512, } impl Blake3Hasher { fn new() -> Self { Self { - hasher: blake3::Hasher::new(), + hasher: Blake2b512::new(), } } - fn consume(self) -> blake3::Hash { - self.hasher.finalize() + fn consume(self) -> [u8; 64] { + self.hasher.finalize().into() } } @@ -72,7 +73,7 @@ pub fn hash_function_impl(attr: TokenStream, input: TokenStream) -> TokenStream let hash = hasher.consume(); let hash_variable_name = &options.const_name; - let hash_bytes = hash.as_bytes(); + let hash_bytes = hash.as_slice(); quote! { pub const #hash_variable_name: &[u8] = &[#(#hash_bytes),*]; diff --git a/packages/vm/Cargo.toml b/packages/vm/Cargo.toml index e626e0c77..cdb659a7a 100644 --- a/packages/vm/Cargo.toml +++ b/packages/vm/Cargo.toml @@ -44,7 +44,7 @@ bytes = "1.4.0" # need a higher version than the one required by Wasmer for clru = "0.6.1" crc32fast = "1.3.2" bech32 = "0.11.0" -blake3 = "1.5" +blake2 = "0.10.6" # Uses the path when built locally; uses the given version from crates.io when published cosmwasm-core = { version = "2.2.0-rc.1", path = "../core" } cosmwasm-std = { version = "2.2.0-rc.1", path = "../std", default-features = false, features = [ diff --git a/packages/vm/src/modules/file_system_cache.rs b/packages/vm/src/modules/file_system_cache.rs index 473c3a1ee..14f3e0cc8 100644 --- a/packages/vm/src/modules/file_system_cache.rs +++ b/packages/vm/src/modules/file_system_cache.rs @@ -1,3 +1,4 @@ +use blake2::{digest::consts::U5, Blake2b, Digest}; use std::fs; use std::hash::Hash; use std::io; @@ -75,7 +76,7 @@ const MODULE_SERIALIZATION_VERSION: &str = "v20"; fn raw_module_version_discriminator() -> String { let hashes = [COST_FUNCTION_HASH]; - let mut hasher = blake3::Hasher::new(); + let mut hasher = Blake2b::::new(); hasher.update(MODULE_SERIALIZATION_VERSION.as_bytes()); hasher.update(wasmer::VERSION.as_bytes()); @@ -84,7 +85,7 @@ fn raw_module_version_discriminator() -> String { hasher.update(hash); } - hasher.finalize().to_hex().to_string() + hex::encode(hasher.finalize()) } /// This version __MUST__ change whenever the module system changes in a way @@ -481,7 +482,7 @@ mod tests { let version = raw_module_version_discriminator(); assert_eq!( version, - "b2a230627e6fd9c14c45aabcf781b58d873dd251fcb004d30e081c8407cad5af" + "5b35f8ce52" ); } }