Skip to content
Merged
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
46 changes: 46 additions & 0 deletions cross-contract-calls-solidity-verifiers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Dependencies
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Build outputs
circuits/target/
circuits/proofs/
contracts/artifacts/
contracts/cache/
frontend/build/
frontend/dist/

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Logs
*.log
logs/

# Temporary files
*.tmp
*.temp


Prover.toml
Verifier.toml
*.wasm
*.vk
*.pk
*.proof
13 changes: 13 additions & 0 deletions cross-contract-calls-solidity-verifiers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Anonymous ZK Poll App

This project demonstrates an anonymous polling application leveraging Zero-Knowledge (ZK) proofs to ensure unique participation without revealing user identities. It utilizes Noir for ZK circuit development.

## Features (Planned)

- Anonymous Voting: Users can cast votes without revealing their identity.

- Unique Participation: ZK proofs prevent double-voting.

- Real-time Results: Poll results are updated in real-time.

- Scalable Architecture: Designed with clear separation of concerns for future expansion.
24 changes: 24 additions & 0 deletions cross-contract-calls-solidity-verifiers/circuits/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "circuits"
type = "bin"
authors = [""]

[dependencies]

# Configuration for the circuit
[circuit]
# Maximum number of constraints (adjust based on your needs)
max_constraints = 100000

# Backend configuration
[backend]
# Use Barretenberg backend (default)
backend = "barretenberg"

# Optimization settings
[optimization]
# Enable optimizations for smaller proof size
optimize_for_size = true

# Enable parallel proving (if supported)
enable_parallel = true
63 changes: 63 additions & 0 deletions cross-contract-calls-solidity-verifiers/circuits/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use dep::std;

global MERKLE_TREE_DEPTH: u32 = 20;

fn main(user_secret: Field,
vote_choice: Field,
merkle_path: [Field; MERKLE_TREE_DEPTH],
merkle_indices: [u1; MERKLE_TREE_DEPTH],
merkle_root: pub Field,
nullifier: pub Field,
poll_id: pub Field,
max_options: pub Field
) {
assert((vote_choice as u32) < (max_options as u32));
assert((vote_choice as u32) >= 0);

// verify that the nullifier is correctly computed
let computed_nullifier = std::hash::pedersen_hash([user_secret, poll_id]);
// std::println(f"Computed nullifier: {computed_nullifier}");
assert(nullifier == computed_nullifier);

// Verify that the user is in the eligible voters merkle tree
let leaf = std::hash::pedersen_hash([user_secret]);
// std::println(f"Leaf hash: {leaf}");
let is_valid_member = verify_merkle_membership(
leaf,
merkle_root,
merkle_path,
merkle_indices
);
assert(is_valid_member);

// ensure user_secret is not 0
assert(user_secret != 0);

std::println(f"Vote verified for poll {poll_id}");
}

fn verify_merkle_membership(
leaf: Field,
root: Field,
path: [Field; MERKLE_TREE_DEPTH],
indices: [u1; MERKLE_TREE_DEPTH]
) -> bool {
let mut current = leaf;

// std::println(f"Starting with leaf: {leaf}");
for i in 0..MERKLE_TREE_DEPTH {
let path_element = path[i];
// std::println(f"Step {i}: current = {current}, path_element = {path_element}");
let is_right = indices[i];

if is_right == 0 {
// Current is left child
current = std::hash::pedersen_hash([current, path_element]);
} else {
// Current is right child
current = std::hash::pedersen_hash([path_element, current]);
}
}
// std::println(f"Final computed root: {current}");
current == root
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Ignore build artifacts from the local tests sub-crate.
/target/

# Ignore backup files creates by cargo fmt.
**/*.rs.bk

# Remove Cargo.lock when creating an executable, leave it for libraries
# More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock
Cargo.lock
34 changes: 34 additions & 0 deletions cross-contract-calls-solidity-verifiers/ink-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "contracts"
version = "0.1.0"
authors = ["[your_name] <[your_email]>"]
edition = "2021"

[dependencies]
const-crypto = "0.3.0"
ink = { version = "6.0.0-beta", default-features = false, features = ["unstable-hostfn"] }
scale-info = { version = "2.11.6", default-features = false, features = ["derive"] }

[dev-dependencies]
ink_e2e = "6.0.0-beta"

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale-info/std",
]
ink-as-dependency = []
e2e-tests = []

[package.metadata.ink-lang]
abi = "all"

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(ink_abi, values("ink", "sol", "all"))'
]
Loading
Loading