Skip to content

Commit 8bb97ff

Browse files
Remove lazy_static dep (#10)
1 parent 184472e commit 8bb97ff

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ repository = "https://github.com/sigp/ethereum_hashing"
99
documentation = "https://docs.rs/ethereum_hashing"
1010
keywords = ["ethereum"]
1111
categories = ["cryptography::cryptocurrencies"]
12+
rust-version = "1.80.0"
1213

1314
[dependencies]
14-
lazy_static = { version = "1.1", optional = true }
1515
ring = "0.17"
1616

1717
[target.'cfg(target_arch = "x86_64")'.dependencies]
@@ -26,4 +26,4 @@ wasm-bindgen-test = "0.3.33"
2626

2727
[features]
2828
default = ["zero_hash_cache"]
29-
zero_hash_cache = ["lazy_static"]
29+
zero_hash_cache = []

src/lib.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub use self::DynamicContext as Context;
1515
use sha2_impl::Sha2CrateImpl;
1616

1717
#[cfg(feature = "zero_hash_cache")]
18-
use lazy_static::lazy_static;
18+
use std::sync::LazyLock;
1919

2020
/// Length of a SHA256 hash in bytes.
2121
pub const HASH_LEN: usize = 32;
@@ -193,18 +193,16 @@ impl Sha256Context for DynamicContext {
193193
pub const ZERO_HASHES_MAX_INDEX: usize = 48;
194194

195195
#[cfg(feature = "zero_hash_cache")]
196-
lazy_static! {
197-
/// Cached zero hashes where `ZERO_HASHES[i]` is the hash of a Merkle tree with 2^i zero leaves.
198-
pub static ref ZERO_HASHES: Vec<Vec<u8>> = {
199-
let mut hashes = vec![vec![0; 32]; ZERO_HASHES_MAX_INDEX + 1];
196+
/// Cached zero hashes where `ZERO_HASHES[i]` is the hash of a Merkle tree with 2^i zero leaves.
197+
pub static ZERO_HASHES: LazyLock<Vec<[u8; HASH_LEN]>> = LazyLock::new(|| {
198+
let mut hashes = vec![[0; HASH_LEN]; ZERO_HASHES_MAX_INDEX + 1];
200199

201-
for i in 0..ZERO_HASHES_MAX_INDEX {
202-
hashes[i + 1] = hash32_concat(&hashes[i], &hashes[i])[..].to_vec();
203-
}
200+
for i in 0..ZERO_HASHES_MAX_INDEX {
201+
hashes[i + 1] = hash32_concat(&hashes[i], &hashes[i]);
202+
}
204203

205-
hashes
206-
};
207-
}
204+
hashes
205+
});
208206

209207
#[cfg(test)]
210208
mod tests {
@@ -231,7 +229,7 @@ mod tests {
231229

232230
#[test]
233231
fn zero_hash_zero() {
234-
assert_eq!(ZERO_HASHES[0], vec![0; 32]);
232+
assert_eq!(ZERO_HASHES[0], [0; 32]);
235233
}
236234
}
237235
}

0 commit comments

Comments
 (0)