Просмотр исходного кода

zkrunner: Support reading witness data from stdin

parazyd 3 лет назад
Родитель
Сommit
2483d088d6
2 измененных файлов с 9 добавлено и 5 удалено
  1. 3 3
      bin/zkrunner/README.md
  2. 6 2
      bin/zkrunner/zkrunner.py

+ 3 - 3
bin/zkrunner/README.md

@@ -13,19 +13,19 @@ work properly.
 Help text:
 Help text:
 
 
 ```
 ```
-$ zkrunner.py -h
+$ ./zkrunner.py -h
 ```
 ```
 
 
 Running a demo:
 Running a demo:
 
 
 ```
 ```
-$ witness_gen.py > witness.json
-$ zkrunner.py -w witness.json opcodes.zk
+$ ./witness_gen.py | ./zkrunner.py -w - opcodes.zk
 ```
 ```
 
 
 The program expects a path to a `witness.json` file containing the
 The program expects a path to a `witness.json` file containing the
 information about witnesses and public inputs for the proof, and a
 information about witnesses and public inputs for the proof, and a
 path to a zkas circuit source code (does not have to be compiled).
 path to a zkas circuit source code (does not have to be compiled).
+The witnesses can also be passed via `stdin`.
 
 
 Once executed, zkrunner will attempt to create and verify the proof.
 Once executed, zkrunner will attempt to create and verify the proof.
 
 

+ 6 - 2
bin/zkrunner/zkrunner.py

@@ -20,6 +20,7 @@ Python tool to prototype zkVM proofs given zkas source code and necessary
 witness values in JSON format.
 witness values in JSON format.
 """
 """
 import json
 import json
+import sys
 from darkfi_sdk.pasta import Fp, Fq, Ep
 from darkfi_sdk.pasta import Fp, Fq, Ep
 from darkfi_sdk.zkas import (MockProver, ZkBinary, ZkCircuit, ProvingKey,
 from darkfi_sdk.zkas import (MockProver, ZkBinary, ZkCircuit, ProvingKey,
                              Proof, VerifyingKey)
                              Proof, VerifyingKey)
@@ -31,8 +32,11 @@ def main(witness_file, source_file, mock=False):
     # Refer to the `witness_gen.py` file to see what the format of this
     # Refer to the `witness_gen.py` file to see what the format of this
     # file should be.
     # file should be.
     print("Decoding witnesses...")
     print("Decoding witnesses...")
-    with open(witness_file, "r", encoding="utf-8") as json_file:
-        witness_data = json.load(json_file)
+    if witness_file == "-":
+        witness_data = json.load(sys.stdin)
+    else:
+        with open(witness_file, "r", encoding="utf-8") as json_file:
+            witness_data = json.load(json_file)
 
 
     # Then we attempt to compile the given zkas code and create a
     # Then we attempt to compile the given zkas code and create a
     # zkVM circuit. This compiling logic happens in the Python bindings'
     # zkVM circuit. This compiling logic happens in the Python bindings'