Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/worldcoin/semaphore-rs
🦀 Rust support library for semaphore
https://github.com/worldcoin/semaphore-rs
managed-by-terraform
Last synced: 3 months ago
JSON representation
🦀 Rust support library for semaphore
- Host: GitHub
- URL: https://github.com/worldcoin/semaphore-rs
- Owner: worldcoin
- License: mit
- Created: 2022-01-28T00:38:41.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-25T20:50:58.000Z (4 months ago)
- Last Synced: 2024-07-26T20:55:55.286Z (4 months ago)
- Topics: managed-by-terraform
- Language: Rust
- Homepage:
- Size: 9.99 MB
- Stars: 121
- Watchers: 30
- Forks: 29
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: mit-license.md
Awesome Lists containing this project
- awesome-circom - worldcoin/semaphore-rs - Rust support library for using semaphore (Projects using Circom / Cryptographic primitives in other languages)
README
# 🦀 semaphore-rs
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.
## Usage
Add this line to your `cargo.toml`:
```toml
semaphore = { git = "https://github.com/worldcoin/semaphore-rs" }
```## 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 `npm exec 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,no_run
use semaphore::{get_supported_depths, hash_to_field, Field, identity::Identity,
poseidon_tree::LazyPoseidonTree, protocol::*};
use num_bigint::BigInt;// generate identity
let mut secret = *b"secret";
let id = Identity::from_secret(&mut secret, None);// Get the first available tree depth. This is controlled by the crate features.
let depth = get_supported_depths()[0];// generate merkle tree
let leaf = Field::from(0);
let mut tree = LazyPoseidonTree::new(depth, leaf).derived();
tree = tree.update(0, &id.commitment());let merkle_proof = tree.proof(0);
let root = tree.root();// change signal and external_nullifier here
let signal_hash = hash_to_field(b"xxx");
let external_nullifier_hash = hash_to_field(b"appId");let nullifier_hash = generate_nullifier_hash(&id, external_nullifier_hash);
let proof = generate_proof(&id, &merkle_proof, external_nullifier_hash, signal_hash).unwrap();
let success = verify_proof(root, nullifier_hash, signal_hash, external_nullifier_hash, &proof, depth).unwrap();assert!(success);
```