Skip to content

Commit

Permalink
Remove integrated heap profiling. Rename crate to halo2_debug.
Browse files Browse the repository at this point in the history
  • Loading branch information
adria0 committed Jun 3, 2024
1 parent ed4c33b commit a1eaa6d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
26 changes: 26 additions & 0 deletions halo2_debug/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
44 changes: 44 additions & 0 deletions halo2_debug/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<OneNg> {
BlockRng::<OneNg>::new(OneNg {})
}

// Random number generator for testing

pub fn test_rng() -> OsRng {
OsRng
}

fn keccak_hex<D: AsRef<[u8]>>(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<D: AsRef<[u8]>>(hex: &str, data: D) {
if cfg!(all(feature = "thread-safe-region", not(coverage))) {
assert_eq!(keccak_hex(data), hex);
}
}

0 comments on commit a1eaa6d

Please sign in to comment.