We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
unsafe
starknet_keccak
1 parent 3a9c18d commit 4b412f7Copy full SHA for 4b412f7
chain/starknet/src/data_source.rs
@@ -380,6 +380,21 @@ fn starknet_keccak(data: &[u8]) -> [u8; 32] {
380
// Remove the first 6 bits
381
hash[0] &= 0b00000011;
382
383
- // Because we know hash is always 32 bytes
384
- *unsafe { &*(hash[..].as_ptr() as *const [u8; 32]) }
+ hash.into()
+}
385
+
386
+#[cfg(test)]
387
+mod tests {
388
+ use super::*;
389
390
+ #[test]
391
+ fn test_starknet_keccak() {
392
+ let expected_hash: [u8; 32] =
393
+ hex::decode("016c11b0b5b808960df26f5bfc471d04c1995b0ffd2055925ad1be28d6baadfd")
394
+ .unwrap()
395
+ .try_into()
396
+ .unwrap();
397
398
+ assert_eq!(starknet_keccak("Hello world".as_bytes()), expected_hash);
399
+ }
400
}
0 commit comments