πŸ¦€ Rust support library for semaphore

Overview

πŸ¦€ semaphore-rs

Rust support library for using semaphore. It's mostly a Rust rewrite of zk-kit, but just focuses on semaphore (for now) and still covers a much smaller scope. It's using ark-circom under the hood for generating the groth16 proofs.

Usage

Add this line to your cargo.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
  2. Install semaphore dependencies cd semaphore && npm install
  3. Compile circuits npm exec ts-node ./scripts/compile-circuits.ts
  4. You'll find the zkey and wasm file in semaphore/build/snark

Example

Example as in src/lib.rs, run with cargo test.

use semaphore::{hash_to_field, Field, identity::Identity, poseidon_tree::PoseidonTree,
    protocol::* };
use num_bigint::BigInt;

// generate identity
let id = Identity::from_seed(b"secret");

// generate merkle tree
let leaf = Field::from(0);
let mut tree = PoseidonTree::new(21, leaf);
tree.set(0, id.commitment());

let merkle_proof = tree.proof(0).expect("proof should exist");
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).unwrap();

assert!(success);
You might also like...
How to bootstrap support for a no_std target

The Embedonomicon How to bootstrap support for a no_std target This book is hosted at https://docs.rust-embedded.org/embedonomicon/ This project is de

βš™οΈ A cute .gitignore generator with support for custom templates
βš™οΈ A cute .gitignore generator with support for custom templates

Gign A Gitignore Generator Table of Contents Examples Install Custom templates Help Examples # This is how you going to use it probably most of the ti

Lapce vue plugin, support vue (SFC) syntax highlight, autocomplate,types check
Lapce vue plugin, support vue (SFC) syntax highlight, autocomplate,types check

Lapce Plugin for Vue (based volar) Preview Usage Required: Lapce version must be greater than 2.0, and you can use Lapce nightly version. click here t

Mommy's here to support you when running cargo~

cargo-mommy Mommy's here to support you when running cargo~ ❀️ Installation Install cargo-mommy like you would any other cargo extension~ cargo inst

serde support for http crate types Request, Response, Uri, StatusCode, HeaderMap

serde extensions for the http crate types Allows serializing and deserializing the following types from http: Response Request HeaderMap StatusCode Ur

A library to compile USDT probes into a Rust library
A library to compile USDT probes into a Rust library

sonde sonde is a library to compile USDT probes into a Rust library, and to generate a friendly Rust idiomatic API around it. Userland Statically Defi

A Rust library for calculating sun positions

sun A rust port of the JS library suncalc. Install Add the following to your Cargo.toml [dependencies] sun = "0.2" Usage pub fn main() { let unixti

A cross-platform serial port library in Rust.

Introduction serialport-rs is a general-purpose cross-platform serial port library for Rust. It provides a blocking I/O interface and port enumeration

A high level diffing library for rust based on diffs
A high level diffing library for rust based on diffs

Similar: A Diffing Library Similar is a dependency free crate for Rust that implements different diffing algorithms and high level interfaces for it.

Comments
  • Move benches to `benches/`

    Move benches to `benches/`

    Had a look through the library and noticed that the crate's benchmarks don't live in the benches/ top level directory, which is the expected directory structure.

    I moved the protocol and mimc benchmarks to their respectives benchmark files (see also the [[benches]] array in Cargo.toml).

    I wasn't 100% sure what the purpose of the println! macros in generate_proof is. They made the output of cargo bench very noisy, so I removed those and moved the code blocks to their own benchmarks (making a wild guess that the println!s were for monitoring the perf of the 2 components of that function).

    I also replaced bench_function with bench_with_inputs where appropriate (because ideally inputs are kept invariant between benchmark runs).

    opened by SuperFluffy 1
  • Fix README link

    Fix README link

    Without this the build fails for me:

    error: couldn't read src/../Readme.md: No such file or directory (os error 2)
     --> src/lib.rs:1:10
      |
    1 | #![doc = include_str!("../Readme.md")]
      |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    opened by oskarth 1
  • fix(semaphore-rs): fix U256 data type origin

    fix(semaphore-rs): fix U256 data type origin

    Recent updates to ethers-core broke compilation of semaphore-rs. Compilation results broken due to no revision hardcoded for ark-circom's ethers-core dependency (which, in turn, is a dependency of semaphore-rs too), hence latest master will be used at each new compilation.

    The reasons of the failure seems to be related with a refactoring of the U256 data type, which before was in primitive_types::U256 and now is moved to (the updated) ethers_core::types::U256.

    This PR updates the reference to the U256 data type to the refactored one now contained in ethers_core and removes the previous dependency primitive_types.

    Note that a solution to this problem is a requirement for all those projects that use semaphore-rs as dependency, since their compilation is now failing.

    @recmo @philsippl

    opened by s1fr0 0
  • chore: update semaphore submodule to https

    chore: update semaphore submodule to https

    Without this CI such as Github action will fail. E.g.:

     error: failed to get `semaphore` as a dependency of package `rln v0.1.0 (/home/runner/work/zerokit/zerokit/rln)`
    
    Caused by:
      failed to load source for dependency `semaphore`
    
    Caused by:
      Unable to update https://github.com/oskarth/semaphore-rs
    
    Caused by:
      failed to update submodule `semaphore`
    
    Caused by:
      failed to fetch submodule `semaphore` from [email protected]:appliedzkp/semaphore.git
    
    Caused by:
      failed to authenticate when downloading repository
    
      * attempted ssh-agent authentication, but no usernames succeeded: `git`
    
      if the git CLI succeeds then `net.git-fetch-with-cli` may help here
      https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
    
    Caused by:
      error authenticating: no auth sock variable; class=Ssh (23)
    Error: Process completed with exit code 101.
    

    Related: https://github.blog/2021-09-01-improving-git-protocol-security-github/

    opened by oskarth 0
Owner
Worldcoin
Accelerating the transition towards a more inclusive and prosperous global economy.
Worldcoin
Error context library with support for type-erased sources and backtraces, targeting full support of all features on stable Rust

Error context library with support for type-erased sources and backtraces, targeting full support of all features on stable Rust, and with an eye towards serializing runtime errors using serde.

Findora Foundation 1 Feb 12, 2022
Utilities to gather data out of roms. Written in Rust. It (should) support all types.

snesutilities Utilities to gather data out of roms. Written in Rust. It (should) support all types. How Have a look at main.rs: use snesutilities::Sne

Layle | Luca 5 Oct 12, 2022
A rewrite of Phonelink for Windows Forms written in Rust, with cross-platform support.

phonelink-rs A rewrite of Phonelink for Windows Forms written in Rust, with cross-platform support. Usage Clone the repository and build, or download

ahsan-a 4 Aug 6, 2022
Board Support Crate for Arduino Leonardo in Rust

Deprecation Note: This crate will soon be deprecated in favor of avr-hal. avr-hal is a new approach to writing the HAL crate, that was designed with s

Rahix 5 May 6, 2021
Universal changelog generator using conventional commit+ with monorepo support. Written in Rust.

chlog Universal changelog generator using conventional commit+ with monorepo support. chlog can generate the changelog from the conventional commits w

Jeff Yang 3 Nov 27, 2022
Rust no_std, embedded_hal board support package for the Electro-Smith Daisy platform.

Daisy Rust no_std, embedded_hal board support package for the Electro-Smith Daisy platform. This project was forked from antoinevg/daisy_bsp. Supporte

zlosynth 5 Dec 4, 2022
Rust usb-device support for ATmega chips

atmega-usbd usb_device support for ATmega microcontrollers. NOTE: This is an experimental library, and certainly not production-ready. Expect bugs, an

Adam Gausmann 20 Jan 8, 2023
OpenAPI support for Poem

Poem OpenAPI Fast and Type-Safe OpenAPI implementation for Poem. Poem-openapi allows you to easily implement APIs that comply with the OpenAPIv3 speci

Poem Web 40 Sep 16, 2021
Use enum to filter something, support | and & operator.

Filter Use enum to filter something, support | and & operator. Just need to implement Filter Trait with filter-macros crate. How to work Example #[add

δΈŠι“Ίε°ε“₯ 9 Feb 8, 2022
`xrandr` for Gnome/wayland, on distros that don't support `wlr-randr`

gnome-randr-rust A reimplementation of xrandr for Gnome on Wayland, especially for systems that don't support wlr-output-management-unstable-v1 (e.g.

Max Ainatchi 40 Dec 21, 2022