add crypto_hash Blob example use sha3
MODIFY
Cargo.lock
Cargo.lock
@@ -2490,6 +2490,7 @@ name = "forkable-jellyfish-merkle"
version = "1.11.9"
dependencies = [
"anyhow",
+ "bcs",
"bcs-ext",
"byteorder 1.4.3",
"criterion",

MODIFY
commons/forkable-jellyfish-merkle/Cargo.toml
commons/forkable-jellyfish-merkle/Cargo.toml
@@ -29,6 +29,7 @@ proptest = "1.0.0"
proptest-derive = "0.3.0"
criterion = "0.3"
starcoin-crypto = { git = "https://github.com/starcoinorg/starcoin-crypto", rev = "d871dfb4216f034ee334a575926c101574d9d6dc"}
+bcs = "0.1.3"
[features]
default = []

MODIFY
commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs
commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs
@@ -982,3 +982,28 @@ where
.next()
.map(|(k, _v)| k.clone())
}
+
+#[test]
+fn blob_crypto_hash_test() -> Result<()> {
+ let buf = hex::decode(
+ "0xfa000000000000007b161ceeef010000000000000000000000000000000000000000000000000000"
+ .strip_prefix("0x")
+ .ok_or_else(|| format_err!("strip_prefix error"))?,
+ )?;
+ let blob = Blob::from(buf);
+ let hash = blob.crypto_hash();
+
+ let name = starcoin_crypto::_serde_name::trace_name::<Blob>()
+ .expect("The `CryptoHasher` macro only applies to structs and enums");
+ assert_eq!(name, "Blob");
+ let salt_prefix: &[u8] = b"STARCOIN::Blob";
+ let ser = bcs::to_bytes(&blob)?;
+ let salt = [
+ HashValue::sha3_256_of(salt_prefix).as_slice(),
+ ser.as_slice(),
+ ]
+ .concat();
+ let hash1 = HashValue::sha3_256_of(&salt[..]);
+ assert_eq!(hash, hash1);
+ Ok(())
+}

add crypto_hash Blob example use sha3 (#3416)