Skip to content

Commit 26bbe4a

Browse files
committed
refactor(target_chains/starknet): check value in Hasher::push_num_bytes
1 parent 8b66d0f commit 26bbe4a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

target_chains/starknet/contracts/src/hash.cairo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ impl HasherPrivateImpl of HasherPrivateTrait {
9797
// Adds specified number of bytes to the buffer.
9898
fn push_num_bytes(ref self: Hasher, value: u64, num_bytes: u8) {
9999
assert!(num_bytes <= 8, "num_bytes too high in Hasher::push_num_bytes");
100+
if num_bytes != 8 {
101+
assert!(
102+
value / one_shift_left_bytes_u64(num_bytes) == 0,
103+
"Hasher::push_num_bytes: value is too large"
104+
);
105+
}
100106
let num_high_bytes = min(num_bytes, 8 - self.num_last_bytes);
101107
let num_low_bytes = num_bytes - num_high_bytes;
102108
let divisor = one_shift_left_bytes_u64(num_low_bytes).try_into().expect(UNEXPECTED_ZERO);
@@ -107,6 +113,12 @@ impl HasherPrivateImpl of HasherPrivateTrait {
107113

108114
fn push_to_last(ref self: Hasher, value: u64, num_bytes: u8) {
109115
assert!(num_bytes <= 8 - self.num_last_bytes, "num_bytes too high in Hasher::push_to_last");
116+
if num_bytes != 8 {
117+
assert!(
118+
value / one_shift_left_bytes_u64(num_bytes) == 0,
119+
"Hasher::push_to_last: value is too large"
120+
);
121+
}
110122
if num_bytes == 8 {
111123
self.last_be = value;
112124
} else {

0 commit comments

Comments
 (0)