From a1eaa6dc884da57f28a8fcaad5e9a88c7dd63ee1 Mon Sep 17 00:00:00 2001 From: adria0 Date: Mon, 3 Jun 2024 15:30:37 +0200 Subject: [PATCH] Remove integrated heap profiling. Rename crate to halo2_debug. --- halo2_debug/Cargo.toml | 26 +++++++++++++++++++++++++ halo2_debug/src/lib.rs | 44 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 halo2_debug/Cargo.toml create mode 100644 halo2_debug/src/lib.rs diff --git a/halo2_debug/Cargo.toml b/halo2_debug/Cargo.toml new file mode 100644 index 000000000..9e71ffdcc --- /dev/null +++ b/halo2_debug/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "halo2_debug" +version = "0.3.0" +authors = [ + "Privacy Scaling Explorations team", +] +edition = "2021" +rust-version = "1.66.0" +description = """ +Halo2 Debug. This package contains utilities for debugging and testing within +the halo2 ecosystem. +""" +license = "MIT OR Apache-2.0" +repository = "https://github.com/privacy-scaling-explorations/halo2" +documentation = "https://privacy-scaling-explorations.github.io/halo2/" +categories = ["cryptography"] +keywords = ["halo", "proofs", "zkp", "zkSNARKs"] + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs", "--html-in-header", "katex-header.html"] + +[dependencies] +tiny-keccak = { version = "2.0.2", features=["keccak"] } +hex = "0.4.3" +rand_core = "0.6.4" diff --git a/halo2_debug/src/lib.rs b/halo2_debug/src/lib.rs new file mode 100644 index 000000000..61f1c3bbe --- /dev/null +++ b/halo2_debug/src/lib.rs @@ -0,0 +1,44 @@ +use rand_core::block::BlockRng; +use rand_core::block::BlockRngCore; +use rand_core::OsRng; +use tiny_keccak::Hasher; + +// One number generator, that can be used as a deterministic Rng, outputing fixed values. +pub struct OneNg {} + +impl BlockRngCore for OneNg { + type Item = u32; + type Results = [u32; 16]; + + fn generate(&mut self, results: &mut Self::Results) { + for elem in results.iter_mut() { + *elem = 1; + } + } +} + +pub fn one_rng() -> BlockRng { + BlockRng::::new(OneNg {}) +} + +// Random number generator for testing + +pub fn test_rng() -> OsRng { + OsRng +} + +fn keccak_hex>(data: D) -> String { + let mut hash = [0u8; 32]; + let mut hasher = tiny_keccak::Keccak::v256(); + hasher.update(data.as_ref()); + hasher.finalize(&mut hash); + hex::encode(hash) +} + +// Check the a test proof against a known hash +// Note that this function is only called in CI in "cargo test --all-fetaures" +pub fn assert_test_proof>(hex: &str, data: D) { + if cfg!(all(feature = "thread-safe-region", not(coverage))) { + assert_eq!(keccak_hex(data), hex); + } +}