-
Notifications
You must be signed in to change notification settings - Fork 34
Add Semaphore over ECDSA #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f9f671e
Add Semaphore
jadnohra c457285
Update Cargo.toml
jadnohra 42ea3dd
Fix rustfmt formatting issues
jadnohra dd9ab71
Fix CI issues: import ordering and remove missing file reference
jadnohra c1cea93
Revert keccak/mod.rs changes to minimize PR diff
jadnohra c7bbbe5
Fix rustfmt: use spaces instead of tabs in circuit.rs
jadnohra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,10 @@ | ||
| use anyhow::Result; | ||
| use binius_examples::{Cli, circuits::semaphore_ecdsa::SemaphoreExample}; | ||
|
|
||
| fn main() -> Result<()> { | ||
| let _tracing_guard = tracing_profile::init_tracing()?; | ||
|
|
||
| Cli::<SemaphoreExample>::new("semaphore_ecdsa") | ||
| .about("Anonymous group membership proofs with nullifiers using ECDSA key derivation") | ||
| .run() | ||
| } |
This file contains hidden or 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,11 @@ | ||
| semaphore_ecdsa circuit | ||
| -- | ||
| Number of gates: 475686 | ||
| Number of evaluation instructions: 563535 | ||
| Number of AND constraints: 609289 | ||
| Number of MUL constraints: 48536 | ||
| Length of value vec: 1048576 | ||
| Constants: 72 | ||
| Inout: 11 | ||
| Witness: 97 | ||
| Internal: 887101 |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| pub mod blake2s; | ||
| pub mod ethsign; | ||
| pub mod keccak; | ||
| pub mod semaphore_ecdsa; | ||
| pub mod sha256; | ||
| pub mod sha512; | ||
| pub mod zklogin; |
This file contains hidden or 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,112 @@ | ||
| use anyhow::{Result, ensure}; | ||
| use binius_frontend::{ | ||
| circuits::semaphore_ecdsa::{IdentityECDSA, MerkleTree, SemaphoreProofECDSA}, | ||
| compiler::{CircuitBuilder, circuit::WitnessFiller}, | ||
| }; | ||
| use clap::Args; | ||
|
|
||
| use crate::ExampleCircuit; | ||
|
|
||
| /// Semaphore anonymous group membership proof with ECDSA key derivation | ||
| pub struct SemaphoreExample { | ||
| circuit: SemaphoreProofECDSA, | ||
| tree_height: usize, | ||
| message_len_bytes: usize, | ||
| scope_len_bytes: usize, | ||
| } | ||
|
|
||
| #[derive(Args, Debug, Clone)] | ||
| pub struct Params { | ||
| /// Height of the Merkle tree (determines max group size = 2^height) | ||
| #[arg(long, default_value_t = 2)] | ||
| pub tree_height: usize, | ||
|
|
||
| /// Maximum message length in bytes | ||
| #[arg(long, default_value_t = 32)] | ||
| pub message_len_bytes: usize, | ||
|
|
||
| /// Maximum scope length in bytes | ||
| #[arg(long, default_value_t = 24)] | ||
| pub scope_len_bytes: usize, | ||
| } | ||
|
|
||
| #[derive(Args, Debug, Clone)] | ||
| pub struct Instance { | ||
| /// Number of group members to create | ||
| #[arg(long, default_value_t = 4)] | ||
| pub group_size: usize, | ||
|
|
||
| /// Index of the member generating the proof (0-based) | ||
| #[arg(long, default_value_t = 1)] | ||
| pub prover_index: usize, | ||
|
|
||
| /// Message to include in the proof | ||
| #[arg(long, default_value = "I vote YES on proposal #42")] | ||
| pub message: String, | ||
|
|
||
| /// Scope for this signal (prevents double-signaling within scope) | ||
| #[arg(long, default_value = "dao_vote_2024_q1")] | ||
| pub scope: String, | ||
| } | ||
|
|
||
| impl ExampleCircuit for SemaphoreExample { | ||
| type Params = Params; | ||
| type Instance = Instance; | ||
|
|
||
| fn build(params: Params, builder: &mut CircuitBuilder) -> Result<Self> { | ||
| ensure!(params.tree_height > 0, "Tree height must be > 0"); | ||
| ensure!(params.message_len_bytes > 0, "Message length must be > 0"); | ||
| ensure!(params.scope_len_bytes > 0, "Scope length must be > 0"); | ||
|
|
||
| let circuit = SemaphoreProofECDSA::new( | ||
| builder, | ||
| params.tree_height, | ||
| params.message_len_bytes, | ||
| params.scope_len_bytes, | ||
| ); | ||
|
|
||
| Ok(Self { | ||
| circuit, | ||
| tree_height: params.tree_height, | ||
| message_len_bytes: params.message_len_bytes, | ||
| scope_len_bytes: params.scope_len_bytes, | ||
| }) | ||
| } | ||
|
|
||
| fn populate_witness(&self, instance: Instance, witness: &mut WitnessFiller) -> Result<()> { | ||
| // Validate inputs | ||
| ensure!(instance.group_size > 0, "Group size must be > 0"); | ||
| ensure!(instance.prover_index < instance.group_size, "Prover index must be < group size"); | ||
| ensure!(instance.group_size <= (1 << self.tree_height), "Group size exceeds tree capacity"); | ||
| ensure!(instance.message.len() <= self.message_len_bytes, "Message too long"); | ||
| ensure!(instance.scope.len() <= self.scope_len_bytes, "Scope too long"); | ||
|
|
||
| // Create ECDSA identities | ||
| let mut identities = Vec::new(); | ||
| for i in 0..instance.group_size { | ||
| let secret_scalar = [((i + 42) as u8); 32]; | ||
| identities.push(IdentityECDSA::new(secret_scalar)); | ||
| } | ||
|
|
||
| // Build Merkle tree | ||
| let mut tree = MerkleTree::new(self.tree_height); | ||
| for identity in &identities { | ||
| tree.add_leaf(identity.commitment()); | ||
| } | ||
|
|
||
| // Get proof for the prover | ||
| let prover_identity = &identities[instance.prover_index]; | ||
| let merkle_proof = tree.proof(instance.prover_index); | ||
|
|
||
| // Populate witness | ||
| self.circuit.populate_witness( | ||
| witness, | ||
| prover_identity, | ||
| &merkle_proof, | ||
| instance.message.as_bytes(), | ||
| instance.scope.as_bytes(), | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.