forked from zcash/halo2
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove integrated heap profiling. Rename crate to halo2_debug.
- Loading branch information
adria0
committed
Jun 3, 2024
1 parent
ed4c33b
commit a1eaa6d
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |