Skip to content
This repository was archived by the owner on Sep 18, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions semaphore/halo2-semaphore/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions semaphore/halo2-semaphore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ edition = "2021"
[dependencies]
halo2_proofs = { git = "https://github.com/privacy-scaling-explorations/halo2.git", features = ["dev-graph"], tag = "v2022_10_22"}
halo2_gadgets = { git = "https://github.com/privacy-scaling-explorations/halo2.git"}
halo2curves = { git = 'https://github.com/privacy-scaling-explorations/halo2curves', tag = '0.3.0' }
snark-verifier = {git = 'https://github.com/privacy-scaling-explorations/snark-verifier'}
halo2_curves = { git = "https://github.com/privacy-scaling-explorations/halo2curves", tag = "0.3.0", package = "halo2curves" }
snark-verifier = {git = 'https://github.com/privacy-scaling-explorations/snark-verifier',features = ["loader_evm", "loader_halo2", "system_halo2"]}
# halo2wrong = {git = 'https://github.com/vuvoth/halo2wrong.git', features = ["dev-graph"]}
transcript = {git = 'https://github.com/vuvoth/halo2wrong', branch = 'export-hasher-chip'}
halo2_wrong_ecc = { git = "https://github.com/privacy-scaling-explorations/halo2wrong", tag = "v2022_10_22", package = "ecc", optional = true }
transcript = {git = 'https://github.com/privacy-scaling-explorations/halo2wrong'}
poseidon = {git = 'https://github.com/privacy-scaling-explorations/poseidon.git', tag = "v2022_10_22"}
rand_core = { version = "0.6", default-features = false }
plotters = { version = "0.3.0" }
rand = "0.8"

itertools = "0.10.3"
itertools = "0.10.3"

[features]
49 changes: 29 additions & 20 deletions semaphore/halo2-semaphore/src/circuit/merkle_tree.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use halo2curves::FieldExt;
use halo2_curves::{FieldExt, bn256::Fr};
use poseidon::Spec;
use transcript::{
halo2::{
Expand Down Expand Up @@ -73,31 +73,40 @@ impl<F: FieldExt> Circuit<F> for MerkleTreeCircuit<F> {
}
}

pub fn gen_merkle_circuit_data(n: u64) -> MerkleTreeCircuit<Fr>{
let mut leaf = Fr::from(123);
let mut merkle_proof = Vec::new();
let mut hasher = poseidon::Poseidon::<Fr, 3, 2>::new(8, 57);

for value in 0..n {
hasher.update(&[leaf, Fr::from(value)]);
leaf = hasher.squeeze();
merkle_proof.push(Fr::from(value));
}

let circuit = MerkleTreeCircuit {
leaf_node: Value::known(Fr::from(123)),
merkle_path: (0..5).map(|_| Value::known(Fr::from(1))).collect(),
hash_root: leaf,
merkle_proof: merkle_proof.iter().map(|v| Value::known(*v)).collect(),
};
circuit
}

#[cfg(test)]
mod tests {
use halo2curves::bn256::Fr;
pub mod tests {
use halo2_curves::{bn256::Fr, FieldExt};
use transcript::{halo2::circuit::Value, maingate::mock_prover_verify};

use super::MerkleTreeCircuit;
use crate::circuit::merkle_tree::gen_merkle_circuit_data;




#[test]
fn test_circuit() {
let mut leaf = Fr::from(123);
let mut merkle_proof = Vec::new();
let mut hasher = poseidon::Poseidon::<Fr, 3, 2>::new(8, 57);

for value in 0..5 {
hasher.update(&[leaf, Fr::from(value)]);
leaf = hasher.squeeze();
merkle_proof.push(Fr::from(value));
}

let circuit = MerkleTreeCircuit {
leaf_node: Value::known(Fr::from(123)),
merkle_path: (0..5).map(|_| Value::known(Fr::from(1))).collect(),
hash_root: leaf,
merkle_proof: merkle_proof.iter().map(|v| Value::known(*v)).collect(),
};

let circuit = gen_merkle_circuit_data(5);

// use plotters::prelude::*;
// let root = BitMapBackend::new("./target/semaphore.png", (1024, 768)).into_drawing_area();
Expand Down
Loading