|
1 | | -use alloy_primitives::FixedBytes; |
2 | 1 | use ethereum_hashing::{hash, hash32_concat, ZERO_HASHES}; |
3 | | -use safe_arith::{ArithError, SafeArith}; |
| 2 | +use safe_arith::ArithError; |
4 | 3 | use std::sync::LazyLock; |
5 | 4 |
|
6 | | -type H256 = alloy_primitives::B256; |
7 | | - |
8 | | -pub trait FixedBytesExtended { |
9 | | - fn from_low_u64_be(value: u64) -> Self; |
10 | | - fn from_low_u64_le(value: u64) -> Self; |
11 | | - fn zero() -> Self; |
12 | | -} |
13 | | - |
14 | | -impl<const N: usize> FixedBytesExtended for FixedBytes<N> { |
15 | | - fn from_low_u64_be(value: u64) -> Self { |
16 | | - let value_bytes = value.to_be_bytes(); |
17 | | - let mut buffer = [0x0; N]; |
18 | | - let bytes_to_copy = value_bytes.len().min(buffer.len()); |
19 | | - // Panic-free because bytes_to_copy <= buffer.len() |
20 | | - let start_index = buffer |
21 | | - .len() |
22 | | - .safe_sub(bytes_to_copy) |
23 | | - .expect("bytes_to_copy <= buffer.len()"); |
24 | | - // Panic-free because start_index <= buffer.len() |
25 | | - // and bytes_to_copy <= value_bytes.len() |
26 | | - buffer |
27 | | - .get_mut(start_index..) |
28 | | - .expect("start_index <= buffer.len()") |
29 | | - .copy_from_slice( |
30 | | - value_bytes |
31 | | - .get(..bytes_to_copy) |
32 | | - .expect("bytes_to_copy <= value_byte.len()"), |
33 | | - ); |
34 | | - Self::from(buffer) |
35 | | - } |
36 | | - |
37 | | - fn from_low_u64_le(value: u64) -> Self { |
38 | | - let value_bytes = value.to_le_bytes(); |
39 | | - let mut buffer = [0x0; N]; |
40 | | - let bytes_to_copy = value_bytes.len().min(buffer.len()); |
41 | | - // Panic-free because bytes_to_copy <= buffer.len() |
42 | | - // and bytes_to_copy <= value_bytes.len() |
43 | | - buffer |
44 | | - .get_mut(..bytes_to_copy) |
45 | | - .expect("bytes_to_copy <= buffer.len()") |
46 | | - .copy_from_slice( |
47 | | - value_bytes |
48 | | - .get(..bytes_to_copy) |
49 | | - .expect("bytes_to_copy <= value_byte.len()"), |
50 | | - ); |
51 | | - Self::from(buffer) |
52 | | - } |
53 | | - |
54 | | - fn zero() -> Self { |
55 | | - Self::ZERO |
56 | | - } |
57 | | -} |
| 5 | +type H256 = fixed_bytes::Hash256; |
| 6 | +pub use fixed_bytes::FixedBytesExtended; |
58 | 7 |
|
59 | 8 | const MAX_TREE_DEPTH: usize = 32; |
60 | 9 | const EMPTY_SLICE: &[H256] = &[]; |
|
0 commit comments