added semaphore submodule
This commit is contained in:
parent
3e7ff80611
commit
c916ecbbe5
|
@ -0,0 +1,3 @@
|
|||
[submodule "semaphore"]
|
||||
path = semaphore
|
||||
url = git@github.com:appliedzkp/semaphore.git
|
24
README.md
24
README.md
|
@ -1,12 +1,21 @@
|
|||
# Semaphore-rs
|
||||
# 🦀 semaphore-rs
|
||||
|
||||
Rust support library for Semaphore
|
||||
Rust support library for using [semaphore](https://github.com/appliedzkp/semaphore). It's mostly a Rust rewrite of [zk-kit](https://github.com/appliedzkp/zk-kit), but just focuses on semaphore (for now) and still covers a much smaller scope. It's using [ark-circom](https://github.com/gakonst/ark-circom) under the hood for generating the groth16 proofs.
|
||||
|
||||
## Building semaphore circuits
|
||||
|
||||
1. Check out submodule (if not done before already): `git submodule update --init --recursive`
|
||||
1. Install semaphore dependencies `cd semaphore && npm install`
|
||||
1. Compile circuits `ts-node ./scripts/compile-circuits.ts`
|
||||
1. You'll find the `zkey` and `wasm` file in `semaphore/build/snark`
|
||||
|
||||
## Example
|
||||
|
||||
Example as in `src/lib.rs`, run with `cargo test`.
|
||||
|
||||
```rust
|
||||
// generate identity
|
||||
let id = Identity::new(b"hello");
|
||||
let id = Identity::new(b"secret");
|
||||
|
||||
// generate merkle tree
|
||||
const LEAF: Hash = Hash::from_bytes_be([0u8; 32]);
|
||||
|
@ -15,9 +24,6 @@ let mut tree = PoseidonTree::new(21, LEAF);
|
|||
let (_, leaf) = id.commitment().to_bytes_be();
|
||||
tree.set(0, leaf.into());
|
||||
|
||||
let root: BigInt = tree.root().into();
|
||||
dbg!(root);
|
||||
|
||||
let merkle_proof = tree.proof(0).expect("proof should exist");
|
||||
let root = tree.root().into();
|
||||
|
||||
|
@ -28,10 +34,12 @@ let external_nullifier = "123".as_bytes();
|
|||
let nullifier_hash = generate_nullifier_hash(&id, external_nullifier);
|
||||
|
||||
let config = SnarkFileConfig {
|
||||
zkey: "./snarkfiles/semaphore.zkey".to_string(),
|
||||
wasm: "./snarkfiles/semaphore.wasm".to_string(),
|
||||
zkey: "./semaphore/build/snark/semaphore_final.zkey".to_string(),
|
||||
wasm: "./semaphore/build/snark/semaphore.wasm".to_string(),
|
||||
};
|
||||
|
||||
let proof = generate_proof(&config, &id, &merkle_proof, external_nullifier, signal).unwrap();
|
||||
let success = verify_proof(&config, &root, &nullifier_hash, signal, external_nullifier, &proof).unwrap();
|
||||
|
||||
assert!(success);
|
||||
```
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 5186a940ff495ff163bd5779631a716d0bf96507
|
12
src/lib.rs
12
src/lib.rs
|
@ -15,7 +15,6 @@ pub type EthereumGroth16Proof = ark_circom::ethereum::Proof;
|
|||
mod test {
|
||||
use super::*;
|
||||
use hash::*;
|
||||
use hex_literal::hex;
|
||||
use identity::*;
|
||||
use poseidon_tree::*;
|
||||
use protocol::*;
|
||||
|
@ -23,12 +22,10 @@ mod test {
|
|||
#[test]
|
||||
fn test_end_to_end() {
|
||||
// generate identity
|
||||
let id = Identity::new(b"hello");
|
||||
let id = Identity::new(b"secret");
|
||||
|
||||
// generate merkle tree
|
||||
const LEAF: Hash = Hash::from_bytes_be(hex!(
|
||||
"0000000000000000000000000000000000000000000000000000000000000000"
|
||||
));
|
||||
const LEAF: Hash = Hash::from_bytes_be([0u8; 32]);
|
||||
|
||||
let mut tree = PoseidonTree::new(21, LEAF);
|
||||
let (_, leaf) = id.commitment().to_bytes_be();
|
||||
|
@ -44,12 +41,13 @@ mod test {
|
|||
let nullifier_hash = generate_nullifier_hash(&id, external_nullifier);
|
||||
|
||||
let config = SnarkFileConfig {
|
||||
zkey: "./snarkfiles/semaphore.zkey".to_string(),
|
||||
wasm: "./snarkfiles/semaphore.wasm".to_string(),
|
||||
zkey: "./semaphore/build/snark/semaphore_final.zkey".to_string(),
|
||||
wasm: "./semaphore/build/snark/semaphore.wasm".to_string(),
|
||||
};
|
||||
|
||||
let proof =
|
||||
generate_proof(&config, &id, &merkle_proof, external_nullifier, signal).unwrap();
|
||||
|
||||
let success = verify_proof(
|
||||
&config,
|
||||
&root.into(),
|
||||
|
|
|
@ -78,21 +78,21 @@ pub fn generate_proof(
|
|||
let inputs = {
|
||||
let mut inputs: HashMap<String, Vec<BigInt>> = HashMap::new();
|
||||
|
||||
inputs.insert("identity_nullifier".to_string(), vec![identity
|
||||
inputs.insert("identityNullifier".to_string(), vec![identity
|
||||
.nullifier
|
||||
.clone()]);
|
||||
inputs.insert("identity_trapdoor".to_string(), vec![identity
|
||||
inputs.insert("identityTrapdoor".to_string(), vec![identity
|
||||
.trapdoor
|
||||
.clone()]);
|
||||
inputs.insert("identity_path_index".to_string(), merkle_proof.path_index());
|
||||
inputs.insert("treePathIndices".to_string(), merkle_proof.path_index());
|
||||
inputs.insert(
|
||||
"path_elements".to_string(),
|
||||
"treeSiblings".to_string(),
|
||||
merkle_proof_to_vec(merkle_proof),
|
||||
);
|
||||
inputs.insert("external_nullifier".to_string(), vec![
|
||||
inputs.insert("externalNullifier".to_string(), vec![
|
||||
hash_external_nullifier(external_nullifier),
|
||||
]);
|
||||
inputs.insert("signal_hash".to_string(), vec![hash_signal(signal)]);
|
||||
inputs.insert("signalHash".to_string(), vec![hash_signal(signal)]);
|
||||
|
||||
inputs
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue