Skip to content

Commit b324edd

Browse files
Seulgi Kimsgkim126
authored andcommitted
Make the slice to create new hash have the same length with the hash
The new hash will check whether the input and the hash to create has the same length.
1 parent fa65a48 commit b324edd

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

state/src/item/metadata.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ impl_address!(TOP, MetadataAddress, PREFIX);
155155

156156
impl MetadataAddress {
157157
pub fn new() -> Self {
158-
Self::from_transaction_hash(H256::from_slice(b"metadata address"), 0)
158+
let mut key = [0u8; 32];
159+
key[0..16].copy_from_slice(b"metadata address");
160+
Self::from_transaction_hash(H256::from_slice(&key), 0)
159161
}
160162
}
161163

@@ -238,4 +240,14 @@ mod tests {
238240
};
239241
rlp_encode_and_decode_test!(metadata);
240242
}
243+
244+
#[test]
245+
fn metadata_address_is_constant() {
246+
let address = MetadataAddress::new();
247+
let expected = [
248+
77u8, 65, 87, 171, 93, 124, 219, 195, 206, 204, 98, 127, 21, 167, 126, 51, 136, 47, 48, 19, 43, 129, 199,
249+
232, 2, 92, 210, 163, 14, 209, 173, 33,
250+
];
251+
assert_eq!(expected, address.as_ref());
252+
}
241253
}

state/src/item/module.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ impl_address!(TOP, ModuleAddress, PREFIX);
9090

9191
impl ModuleAddress {
9292
pub fn new(storage_id: StorageId) -> Self {
93-
Self::from_transaction_hash(H256::from_slice(b"module"), storage_id.into())
93+
let mut key = [0u8; 32];
94+
key[0..6].copy_from_slice(b"module");
95+
Self::from_transaction_hash(H256::from_slice(&key), storage_id.into())
9496
}
9597
}
9698

0 commit comments

Comments
 (0)