From a17ec45498c3084183bd3bb9084eaa6331513a81 Mon Sep 17 00:00:00 2001 From: olesHolem Date: Wed, 18 Oct 2023 04:11:49 +0300 Subject: [PATCH 1/2] fixed sha3 version and fixed tests --- Cargo.toml | 3 ++- src/data_structures/alg_binary_tree/dense_tree.rs | 6 +++--- src/glue/code_unpacker_sha256/mod.rs | 12 +++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2881b76..e07dd64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,8 @@ resolver = "2" # franklin-crypto = {path = "../franklin-crypto", features = ["plonk", "multicore"]} franklin-crypto = {git = "https://github.com/matter-labs/franklin-crypto", branch = "dev", features = ["multicore"]} sha2 = "0.10" -sha3 = "0.10" +# sha3 = "0.10" +sha3 = { git = "https://github.com/RustCrypto/hashes.git", rev = "7a187e934c1f6c68e4b4e5cf37541b7a0d64d303" } hex = "*" once_cell = "*" derivative = "*" diff --git a/src/data_structures/alg_binary_tree/dense_tree.rs b/src/data_structures/alg_binary_tree/dense_tree.rs index d70c2b9..9908131 100644 --- a/src/data_structures/alg_binary_tree/dense_tree.rs +++ b/src/data_structures/alg_binary_tree/dense_tree.rs @@ -192,13 +192,13 @@ mod tests { >::new(¶ms); let mut leaf_hashes = vec![Fr::zero(); 8]; - let one = Fr::from_str("1").unwrap(); - leaf_hashes[0] = one; + leaf_hashes[0] = Fr::one(); let new_tree = BinaryTree::::create_from_leaf_hashes(&leaf_hashes, hasher); assert_eq!( new_tree.get_commitment().to_string().as_str(), - "Fr(0x2a30c843f2912ccc50f7b5baab078e548dd5df3fdb07199d1413c437b0997dee)" + // "Fr(0x2a30c843f2912ccc50f7b5baab078e548dd5df3fdb07199d1413c437b0997dee)" + "Fr(0x113bf1fa2ddb05cf4659651dc6a6c602a8f29dfde19f288e066c97b020fdc9d8)" ); } diff --git a/src/glue/code_unpacker_sha256/mod.rs b/src/glue/code_unpacker_sha256/mod.rs index faefcc0..2c2ee1e 100644 --- a/src/glue/code_unpacker_sha256/mod.rs +++ b/src/glue/code_unpacker_sha256/mod.rs @@ -652,9 +652,15 @@ mod test { let mut code_hash_in_internal_format = [0u8; 32]; let length_in_words = (input_length / 32) as u16; let length_in_words_le = length_in_words.to_be_bytes(); - code_hash_in_internal_format[0] = length_in_words_le[0]; - code_hash_in_internal_format[1] = length_in_words_le[1]; - code_hash_in_internal_format[2..].copy_from_slice(&code_hash.as_slice()[2..]); + + use zkevm_opcode_defs::VersionedHashDef; + use zkevm_opcode_defs::versioned_hash::ContractCodeSha256; + + code_hash_in_internal_format[0] = ContractCodeSha256::VERSION_BYTE; + code_hash_in_internal_format[1] = 0; + code_hash_in_internal_format[2] = length_in_words_le[0]; + code_hash_in_internal_format[3] = length_in_words_le[1]; + code_hash_in_internal_format[4..].copy_from_slice(&code_hash.as_slice()[4..]); let code_hash = UInt256::constant_from_biguint(BigUint::from_bytes_be(&code_hash_in_internal_format)); From 479213f0deaed7d6c86c6a014fe640573464dc30 Mon Sep 17 00:00:00 2001 From: olesHolem Date: Wed, 18 Oct 2023 04:12:43 +0300 Subject: [PATCH 2/2] cargo fmt --- src/glue/code_unpacker_sha256/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/glue/code_unpacker_sha256/mod.rs b/src/glue/code_unpacker_sha256/mod.rs index 2c2ee1e..dcb53b3 100644 --- a/src/glue/code_unpacker_sha256/mod.rs +++ b/src/glue/code_unpacker_sha256/mod.rs @@ -653,9 +653,9 @@ mod test { let length_in_words = (input_length / 32) as u16; let length_in_words_le = length_in_words.to_be_bytes(); - use zkevm_opcode_defs::VersionedHashDef; use zkevm_opcode_defs::versioned_hash::ContractCodeSha256; - + use zkevm_opcode_defs::VersionedHashDef; + code_hash_in_internal_format[0] = ContractCodeSha256::VERSION_BYTE; code_hash_in_internal_format[1] = 0; code_hash_in_internal_format[2] = length_in_words_le[0];