mirror of
https://github.com/MPCStats/zk-stats-lib.git
synced 2026-01-09 13:38:02 -05:00
fix(cli): use latest core functions and add more clis
This commit is contained in:
4
poetry.lock
generated
4
poetry.lock
generated
@@ -159,7 +159,7 @@ tests = ["asttokens (>=2.1.0)", "ipython", "pytest", "coverage", "coverage-enabl
|
||||
|
||||
[[package]]
|
||||
name = "ezkl"
|
||||
version = "5.0.8"
|
||||
version = "7.0.0"
|
||||
description = ""
|
||||
category = "main"
|
||||
optional = false
|
||||
@@ -973,7 +973,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-ena
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.9"
|
||||
content-hash = "8ee9be283f6db12adbeda6af40dca6847eb117df36f6b6ace0d472c15e58c91d"
|
||||
content-hash = "03cd7c0d02c4808c77b5a68746bb6b1ebbc014edabea0ed29e9d490e07863029"
|
||||
|
||||
[metadata.files]
|
||||
appnope = []
|
||||
|
||||
@@ -6,7 +6,7 @@ authors = ["Jern Kunpittaya", "Kevin Chia"]
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
ezkl = "5.0.8"
|
||||
ezkl = "7.0.0"
|
||||
torch = "^2.1.1"
|
||||
requests = "^2.31.0"
|
||||
scipy = "^1.11.4"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import click
|
||||
|
||||
from .core import prover_gen_proof, prover_setup, load_model, verifier_verify
|
||||
from .core import prover_gen_proof, prover_setup, load_model, verifier_verify, gen_data_commitment
|
||||
|
||||
cwd = os.getcwd()
|
||||
# TODO: Should make this configurable
|
||||
@@ -38,7 +38,6 @@ def prove(model_path: str, data_path: str):
|
||||
"default",
|
||||
"resources",
|
||||
settings_path,
|
||||
srs_path,
|
||||
vk_path,
|
||||
pk_path,
|
||||
)
|
||||
@@ -51,20 +50,30 @@ def prove(model_path: str, data_path: str):
|
||||
settings_path,
|
||||
proof_path,
|
||||
pk_path,
|
||||
srs_path,
|
||||
)
|
||||
print("Finished generating proof")
|
||||
verifier_verify(proof_path, settings_path, vk_path, srs_path)
|
||||
verifier_verify(proof_path, settings_path, vk_path)
|
||||
print("Proof path:", proof_path)
|
||||
print("Settings path:", settings_path)
|
||||
print("Verification key path:", vk_path)
|
||||
print("SRS path:", srs_path)
|
||||
|
||||
|
||||
@click.command()
|
||||
def verify():
|
||||
# TODO: Skip verify CLI in DataProvider for now. It's verified in `prove` already
|
||||
raise NotImplementedError
|
||||
@click.argument('proof_path')
|
||||
@click.argument('settings_path')
|
||||
@click.argument('vk_path')
|
||||
def verify(proof_path: str, settings_path: str, vk_path: str):
|
||||
verifier_verify(proof_path, settings_path, vk_path)
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument('data_path')
|
||||
def commit(data_path: str):
|
||||
"""
|
||||
Now we just assume the data is a list of floats. We should be able to
|
||||
"""
|
||||
commitment = gen_data_commitment(data_path)
|
||||
print("Commitment:", hex(commitment))
|
||||
|
||||
|
||||
def main():
|
||||
@@ -74,6 +83,7 @@ def main():
|
||||
# Register commands
|
||||
cli.add_command(prove)
|
||||
cli.add_command(verify)
|
||||
cli.add_command(commit)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -262,3 +262,18 @@ def verifier_verify(proof_path, settings_path, vk_path):
|
||||
|
||||
assert res == True
|
||||
print("verified")
|
||||
|
||||
|
||||
def gen_data_commitment(data_path: str) -> int:
|
||||
"""
|
||||
Generate a commitment to the data. The data can only be a list of floats now.
|
||||
"""
|
||||
|
||||
with open(data_path) as f:
|
||||
data_json = json.load(f)
|
||||
data_list = data_json["input_data"][0]
|
||||
print("Data list:", data_list)
|
||||
data_transformed = [ezkl.float_to_vecu64(x, 7) for x in data_list]
|
||||
hashed = ezkl.poseidon_hash(data_transformed)[0]
|
||||
print("hashed: ", hashed)
|
||||
return int(ezkl.vecu64_to_felt(hashed), 16)
|
||||
|
||||
Reference in New Issue
Block a user