Skip to content

Commit 0f068fe

Browse files
Merge pull request #22 from zksecurity/noir-runner
Implement Noir runner
2 parents 8a0fdda + 97d52c7 commit 0f068fe

File tree

11 files changed

+666
-284
lines changed

11 files changed

+666
-284
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,49 @@ pytest
3535
python scripts/lint_and_tests.py
3636
```
3737

38+
### Circom
39+
40+
In order to target Circom implementation, you need to install Circom and SnarkJS (optional)
41+
42+
Circom:
43+
44+
```
45+
git clone https://github.com/iden3/circom.git
46+
cargo build --release
47+
cargo install --path circom
48+
```
49+
50+
SnarkJS:
51+
52+
```
53+
npm install -g snarkjs@latest
54+
```
55+
56+
### Noir
57+
58+
In order to target Noir implementation, you need to install Noir as follows:
59+
60+
```
61+
curl -L https://raw.githubusercontent.com/noir-lang/noirup/refs/heads/main/install | bash
62+
noirup
63+
```
64+
65+
Also, you need to custom installation of zk-regex as follows:
66+
67+
```
68+
git clone git@github.com:Mach-34/noir-zk-regex.git
69+
cd noir-zk-regex
70+
git checkout fix/efficient-substrings
71+
cargo install --path packages/compiler/
72+
```
73+
74+
Optionally, install Barretenberg if we want to test the proving/verification as well:
75+
76+
```
77+
curl -L https://raw.githubusercontent.com/AztecProtocol/aztec-packages/refs/heads/master/barretenberg/bbup/install | bash
78+
bbup
79+
```
80+
3881
## Example Run
3982

4083
### Fuzzing
@@ -70,3 +113,13 @@ python src/zkregex_fuzzer/cli.py fuzz \
70113
--fuzzer grammar \
71114
--circom-library ../zk-regex/node_modules/circomlib ../zk-regex/node_modules/
72115
```
116+
117+
or for noir with the database fuzzer
118+
119+
```
120+
python src/zkregex_fuzzer/cli.py fuzz \
121+
--oracle valid \
122+
--target noir \
123+
--valid-input-generator exrex \
124+
--fuzzer database
125+
```

src/zkregex_fuzzer/cli.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
SnarkjsSubprocess,
2020
ZkRegexSubprocess,
2121
)
22+
from zkregex_fuzzer.runner.subprocess import BarretenbergSubprocess, NoirSubprocess
2223

2324

2425
def fuzz_parser():
@@ -50,6 +51,11 @@ def fuzz_parser():
5051
choices=list(VALID_INPUT_GENERATORS.keys()),
5152
help=f"The valid input generator to use for the fuzzer (options: {list(VALID_INPUT_GENERATORS.keys())}).",
5253
)
54+
parser.add_argument(
55+
"--seed",
56+
default=str(uuid.uuid4()),
57+
help="Seed for random generator (default: UUIDv4)",
58+
)
5359
parser.add_argument(
5460
"--save",
5561
choices=[status.name for status in HarnessStatus],
@@ -75,7 +81,7 @@ def fuzz_parser():
7581
help="Maximum depth of recursion in the grammar (default: 5).",
7682
)
7783
parser.add_argument(
78-
"--circom-max-input-size",
84+
"--max-input-size",
7985
type=int,
8086
default=600,
8187
help="Maximum size of the circuit input (default: 600).",
@@ -99,6 +105,19 @@ def fuzz_parser():
99105
help="Path to the ptau (powers-of-tau) file for the proving step",
100106
)
101107

108+
parser.add_argument(
109+
"--noir-prove",
110+
action="store_true",
111+
help="Run the proving and verification step with Barretenberg.",
112+
)
113+
114+
parser.add_argument(
115+
"--logger-level",
116+
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
117+
default="INFO",
118+
help="Set the logger level (default: INFO).",
119+
)
120+
102121
return parser
103122

104123

@@ -112,6 +131,12 @@ def reproduce_parser():
112131
help="Path to the target directory output that want to be reproduced (support wildcard pattern).",
113132
required=True,
114133
)
134+
parser.add_argument(
135+
"--logger-level",
136+
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
137+
default="INFO",
138+
help="Set the logger level (default: INFO).",
139+
)
115140

116141
return parser
117142

@@ -123,13 +148,15 @@ def do_fuzz(args):
123148

124149
if args.target == "circom":
125150
try:
126-
circom_version = CircomSubprocess.get_installed_version()
127-
snarkjs_version = SnarkjsSubprocess.get_installed_version()
128151
zk_regex_version = ZkRegexSubprocess.get_installed_version()
152+
circom_version = CircomSubprocess.get_installed_version()
129153
print("-" * 80)
130-
print(f"Circom: {circom_version}")
131-
print(f"SnarkJS: {snarkjs_version}")
132154
print(f"zk-regex: {zk_regex_version}")
155+
print(f"Circom: {circom_version}")
156+
if args.circom_prove:
157+
snarkjs_version = SnarkjsSubprocess.get_installed_version()
158+
print(f"SnarkJS: {snarkjs_version}")
159+
133160
except ValueError as e:
134161
print(e)
135162
exit(1)
@@ -159,6 +186,20 @@ def do_fuzz(args):
159186
print(f"Path to ptau file {ptau_path} does not exist.")
160187
exit(1)
161188

189+
elif args.target == "noir":
190+
try:
191+
zk_regex_version = ZkRegexSubprocess.get_installed_version()
192+
noir_version = NoirSubprocess.get_installed_version()
193+
print("-" * 80)
194+
print(f"zk-regex: {zk_regex_version}")
195+
print(f"Noir: {noir_version}")
196+
if args.noir_prove:
197+
bb_version = BarretenbergSubprocess.get_installed_version()
198+
print(f"Barretenberg: {bb_version}")
199+
except ValueError as e:
200+
print(e)
201+
exit(1)
202+
162203
print("-" * 80)
163204
print(f"Fuzzing with {args.fuzzer} fuzzer.")
164205
print("=" * 80)
@@ -173,9 +214,7 @@ def do_fuzz(args):
173214
kwargs = vars(args)
174215

175216
# set global seed
176-
seed = str(uuid.uuid4())
177-
kwargs["seed"] = seed
178-
random.seed(seed)
217+
random.seed(args.seed)
179218

180219
if args.fuzzer == "grammar":
181220
fuzz_with_grammar(
@@ -203,12 +242,6 @@ def do_reproduce(args):
203242

204243
def main():
205244
parser = argparse.ArgumentParser()
206-
parser.add_argument(
207-
"--logger-level",
208-
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
209-
default="INFO",
210-
help="Set the logger level (default: INFO).",
211-
)
212245

213246
subparser = parser.add_subparsers(dest="subcommand")
214247
subparser.add_parser(

src/zkregex_fuzzer/configs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from zkregex_fuzzer.grammar import REGEX_GRAMMAR
22
from zkregex_fuzzer.regexgen import DatabaseRegexGenerator, GrammarRegexGenerator
3-
from zkregex_fuzzer.runner import CircomRunner, PythonReRunner
3+
from zkregex_fuzzer.runner import CircomRunner, NoirRunner, PythonReRunner
44
from zkregex_fuzzer.vinpgen import ExrexGenerator, GrammarBasedGenerator, RstrGenerator
55

66
TARGETS = {
77
"circom": CircomRunner,
8+
"noir": NoirRunner,
89
"python_re": PythonReRunner,
910
}
1011

src/zkregex_fuzzer/fuzzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def fuzz_with_regexes(
6565
"""
6666
Fuzz test with pre-seeded regexes.
6767
"""
68-
max_input_size = kwargs.get("circom_max_input_size", None)
68+
max_input_size = kwargs.get("max_input_size", None)
6969
oracle, oracle_generator = oracle_params
7070
if oracle:
7171
generator = VALID_INPUT_GENERATORS[oracle_generator]

src/zkregex_fuzzer/grammar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
TODO:
2020
- Add more grammars.
2121
"""
22+
2223
import string
2324
from typing import List
2425

src/zkregex_fuzzer/report.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""
22
Implements the logic for generating a report from the fuzzing results.
33
"""
4+
45
from zkregex_fuzzer.harness import HarnessResult
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .base_runner import RegexCompileError, RegexRunError, Runner
22
from .circom import CircomRunner
3+
from .noir import NoirRunner
34
from .python import PythonReRunner

0 commit comments

Comments
 (0)