mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-15 02:42:38 +00:00
Publish ssz_types (and deps) to crates.io (#468)
* Rename `hashing` crate to `eth2_hashing` * Add license, desc to eth2_hashing Cargo.toml * Remove merkle root from eth2 hashing * Remove old benches folder (zombied from old branch) * Add docs to eth2_hashing * Prepare tree_hash for publishing on crates.io * Update deps to use crates.io instead of paths * Update all crates to pull ssz from crates.io * Remove cached_tree_hash, add patches to manifest * Fix compile error in benches * Remove unused code * Fix fake_crypto compile error
This commit is contained in:
2
eth2/utils/eth2_hashing/.cargo/config
Normal file
2
eth2/utils/eth2_hashing/.cargo/config
Normal file
@@ -0,0 +1,2 @@
|
||||
[target.wasm32-unknown-unknown]
|
||||
runner = 'wasm-bindgen-test-runner'
|
||||
16
eth2/utils/eth2_hashing/Cargo.toml
Normal file
16
eth2/utils/eth2_hashing/Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "eth2_hashing"
|
||||
version = "0.1.0"
|
||||
authors = ["Paul Hauner <paul@paulhauner.com>"]
|
||||
edition = "2018"
|
||||
license = "Apache-2.0"
|
||||
description = "Hashing primitives used in Ethereum 2.0"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
ring = "0.14.6"
|
||||
|
||||
[dev-dependencies]
|
||||
rustc-hex = "2.0.1"
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
|
||||
wasm-bindgen-test = "0.2.47"
|
||||
4
eth2/utils/eth2_hashing/fuzz/.gitignore
vendored
Normal file
4
eth2/utils/eth2_hashing/fuzz/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
target
|
||||
corpus
|
||||
artifacts
|
||||
22
eth2/utils/eth2_hashing/fuzz/Cargo.toml
Normal file
22
eth2/utils/eth2_hashing/fuzz/Cargo.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
[package]
|
||||
name = "hashing-fuzz"
|
||||
version = "0.0.1"
|
||||
authors = ["Automatically generated"]
|
||||
publish = false
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
[dependencies.hashing]
|
||||
path = ".."
|
||||
[dependencies.libfuzzer-sys]
|
||||
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
|
||||
|
||||
# Prevent this from interfering with workspaces
|
||||
[workspace]
|
||||
members = ["."]
|
||||
|
||||
[[bin]]
|
||||
name = "fuzz_target_hash"
|
||||
path = "fuzz_targets/fuzz_target_hash.rs"
|
||||
@@ -0,0 +1,9 @@
|
||||
#![no_main]
|
||||
#[macro_use] extern crate libfuzzer_sys;
|
||||
extern crate hashing;
|
||||
|
||||
use hashing::hash;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let _result = hash(data);
|
||||
});
|
||||
44
eth2/utils/eth2_hashing/src/lib.rs
Normal file
44
eth2/utils/eth2_hashing/src/lib.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
//! Provides a simple hash function utilizing `ring::digest::SHA256`.
|
||||
//!
|
||||
//! The purpose of this crate is to provide an abstraction to whatever hash function Ethereum
|
||||
//! 2.0 is using. The hash function has been subject to change during the specification process, so
|
||||
//! defining it once in this crate makes it easy to replace.
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use ring::digest::{digest, SHA256};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
/// Returns the digest of `input`.
|
||||
///
|
||||
/// Uses `ring::digest::SHA256`.
|
||||
pub fn hash(input: &[u8]) -> Vec<u8> {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let h = digest(&SHA256, input).as_ref().into();
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
let h = Sha256::digest(input).as_ref().into();
|
||||
|
||||
h
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rustc_hex::FromHex;
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
#[cfg_attr(not(target_arch = "wasm32"), test)]
|
||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
|
||||
fn test_hashing() {
|
||||
let input: Vec<u8> = b"hello world".as_ref().into();
|
||||
|
||||
let output = hash(input.as_ref());
|
||||
let expected_hex = "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9";
|
||||
let expected: Vec<u8> = expected_hex.from_hex().unwrap();
|
||||
assert_eq!(expected, output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user