Skip to content

Commit edd47a2

Browse files
author
tilo-14
committed
refactor(zk): Remove unused deps and fix circuit imports
- zk-nullifier: Remove unused blake3 dependency - zk-id: Update merkle proof circuit import path - zk-merkle-proof: Add Anchor.toml, fix circuit import
1 parent 8bab0d0 commit edd47a2

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

zk/zk-id/circuits/merkle_proof.circom

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma circom 2.0.0;
33
include "../node_modules/circomlib/circuits/poseidon.circom";
44
include "../node_modules/circomlib/circuits/bitify.circom";
55
include "../node_modules/circomlib/circuits/switcher.circom";
6+
include "../node_modules/circomlib/circuits/comparators.circom";
67

78
// Merkle Proof Verification Template
89
// Verifies that a leaf is in a Merkle tree with a given root
@@ -12,10 +13,16 @@ template MerkleProof(levels) {
1213
signal input leafIndex;
1314
signal output root;
1415

16+
// Range check: leafIndex < 2^levels
17+
component indexRange = LessThan(levels + 1);
18+
indexRange.in[0] <== leafIndex;
19+
indexRange.in[1] <== 1 << levels;
20+
indexRange.out === 1;
21+
1522
component switcher[levels];
1623
component hasher[levels];
1724

18-
component indexBits = Num2Bits(levels);
25+
component indexBits = Num2Bits_strict(levels);
1926
indexBits.in <== leafIndex;
2027

2128
for (var i = 0; i < levels; i++) {

zk/zk-id/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(unexpected_cfgs)]
22
#![allow(deprecated)]
33

4-
use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize};
4+
use anchor_lang::prelude::*;
55
use borsh::{BorshDeserialize, BorshSerialize};
66
use groth16_solana::groth16::Groth16Verifier;
77
use light_hasher::to_byte_array::ToByteArray;

zk/zk-merkle-proof/Anchor.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[toolchain]
2+
anchor_version = "0.31.1"
3+
4+
[features]
5+
resolution = true
6+
skip-lint = false
7+
8+
[programs.localnet]
9+
zk_merkle_proof = "MPzkYomvQc4VQPwMr6bFduyWRQZVCh5CofgDC4dFqJp"
10+
11+
[registry]
12+
url = "https://api.apr.dev"
13+
14+
[provider]
15+
cluster = "localnet"
16+
wallet = "~/.config/solana/id.json"
17+
18+
[scripts]
19+
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
20+

zk/zk-merkle-proof/circuits/merkle_proof.circom

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,23 @@ pragma circom 2.0.0;
33
include "../node_modules/circomlib/circuits/poseidon.circom";
44
include "../node_modules/circomlib/circuits/bitify.circom";
55
include "../node_modules/circomlib/circuits/switcher.circom";
6+
include "../node_modules/circomlib/circuits/comparators.circom";
67

78
template MerkleProof(levels) {
89
signal input leaf;
910
signal input pathElements[levels];
1011
signal input leafIndex;
1112
signal output root;
1213

14+
// Range check: leafIndex < 2^levels
15+
component indexRange = LessThan(levels + 1);
16+
indexRange.in[0] <== leafIndex;
17+
indexRange.in[1] <== 1 << levels;
18+
indexRange.out === 1;
19+
1320
component switcher[levels];
1421
component hasher[levels];
15-
component indexBits = Num2Bits(levels);
22+
component indexBits = Num2Bits_strict(levels);
1623
indexBits.in <== leafIndex;
1724

1825
for (var i = 0; i < levels; i++) {

zk/zk-nullifier/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zk/zk-nullifier/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ test-sbf = []
1313
idl-build = ["anchor-lang/idl-build"]
1414

1515
[dependencies]
16-
blake3 = "=1.5.5"
1716
anchor-lang = "0.31.1"
1817
borsh = "0.10.4"
1918
light-sdk = { version = "0.17.1", features = ["anchor"] }

0 commit comments

Comments
 (0)