Skip to content

Commit 136a17c

Browse files
Add more debug logging and --logger-level option
1 parent dc8bc61 commit 136a17c

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
output*
12
.vscode
23
tags
34
*.*.swp

src/zkregex_fuzzer/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,17 @@ def main():
8484
type=str,
8585
help="Path to the ptau (powers-of-tau) file for the proving step"
8686
)
87+
parser.add_argument(
88+
"--logger-level",
89+
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
90+
default="INFO",
91+
help="Set the logger level (default: INFO)."
92+
)
8793

8894
args = parser.parse_args()
8995

96+
logger.setLevel(args.logger_level)
97+
9098
if args.oracle == "valid" and not args.valid_input_generator:
9199
print("Valid input generator is required for valid oracle.")
92100
exit(1)

src/zkregex_fuzzer/runner/circom.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ def compile(self, regex: str) -> None:
251251
"""
252252
Compile the regex.
253253
"""
254+
logger.debug(f"Compiling regex starts")
254255
# Create JSON for the regex for zk-regex
255256
base_json = {
256257
"parts": []
@@ -269,25 +270,31 @@ def compile(self, regex: str) -> None:
269270
circom_file_path = tempfile.NamedTemporaryFile(suffix=".circom", delete=False).name
270271

271272
# Call zk-regex to generate the circom code
273+
logger.debug(f"Generating circom code starts")
272274
ZkRegexSubprocess.compile(json_file_path, circom_file_path, self._template_name)
275+
logger.debug(f"Generating circom code ends")
273276

274277
# Append the circom file to include the main function
275278
with open(circom_file_path, 'a') as f:
276279
f.write("\n\n")
277280
f.write("component main {public [msg]} = " + f"{self._template_name}({self._circom_max_input_size});")
278281

279282
# Compile the circom code to wasm
283+
logger.debug(f"Compiling circom code starts")
280284
self._wasm_path, self._r1cs_path = CircomSubprocess.compile(circom_file_path, self._link_path)
285+
logger.debug(f"Compiling circom code ends")
281286

282287
# Also setup the proving and verification key if the flag is set
283288
if self._run_the_prover:
284289
self._zkey_path = SnarkjsSubprocess.setup_zkey(self._r1cs_path, self._ptau_path)
285290
self._vkey_path = SnarkjsSubprocess.export_verification_key(self._zkey_path)
291+
logger.debug(f"Compiling regex ends")
286292

287293
def match(self, input: str) -> tuple[bool, str]:
288294
"""
289295
Match the regex on an input.
290296
"""
297+
logger.debug(f"Matching regex starts")
291298
# Convert input to list of decimal ASCII values and pad input with zeroes
292299
numeric_input = [ord(c) for c in input] + [0] * (self._circom_max_input_size - len(input))
293300

@@ -298,10 +305,12 @@ def match(self, input: str) -> tuple[bool, str]:
298305

299306
# Skip if input is larger than circuit max input size
300307
if len(numeric_input) > self._circom_max_input_size:
301-
raise RegexRunError(f"Input too large for input: {input}")
308+
raise RegexRunError(f"Input too large for input: {len(numeric_input)}")
302309

303310
# Generate the witness
311+
logger.debug(f"Generating witness starts")
304312
witness_path = SnarkjsSubprocess.witness_gen(self._wasm_path, input_path)
313+
logger.debug(f"Generating witness ends")
305314
# Remove input file
306315
Path(input_path).unlink()
307316

@@ -320,6 +329,7 @@ def match(self, input: str) -> tuple[bool, str]:
320329

321330
# Return the output of the match
322331
output = int(result[1])
332+
logger.debug(f"Matching regex ends")
323333
return output == 1, ""
324334

325335
def clean(self):

src/zkregex_fuzzer/vinpgen.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def generate_many(self, n: int) -> List[str]:
5353
If the generator is able to generate less than n valid inputs,
5454
it will silently return the number of valid inputs generated.
5555
"""
56+
logger.debug("Start generating valid inputs.")
5657
valid_inputs = []
5758
attempts = 0
5859
logger.debug(f"Generating {n} valid inputs for the regex: {self.regex} with {self._max_attempts} attempts using {self.__class__.__name__}.")
@@ -66,7 +67,8 @@ def generate_many(self, n: int) -> List[str]:
6667
attempts += 1
6768
if len(valid_inputs) == 0:
6869
raise ValueError("Failed to generate any valid input for the regex.")
69-
logger.debug(f"Generated valid inputs for the regex: {valid_inputs}.")
70+
#logger.debug(f"Generated valid inputs for the regex: {valid_inputs}.")
71+
logger.debug("Finished generating valid inputs.")
7072
return valid_inputs
7173

7274
@abstractmethod

0 commit comments

Comments
 (0)