-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OMR_AVS 002 commandd line based prover
- Loading branch information
Showing
20 changed files
with
1,735 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"type":"function","name":"verifyProof","inputs":[{"internalType":"bytes","name":"proof","type":"bytes"},{"internalType":"uint256[]","name":"instances","type":"uint256[]"}],"outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable"}] |
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import torch | ||
from torch import nn | ||
|
||
class Model(nn.Module): | ||
def __init__(self): | ||
super(Model, self).__init__() | ||
|
||
def forward(self, x): | ||
return [torch.max(x)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"input_data": [ | ||
[ | ||
1.0, | ||
10.0, | ||
1.0, | ||
1.0, | ||
2.0 | ||
] | ||
] | ||
} |
Binary file not shown.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"run_args": { | ||
"tolerance": { | ||
"val": 0.0, | ||
"scale": 1.0 | ||
}, | ||
"input_scale": 2, | ||
"param_scale": 2, | ||
"scale_rebase_multiplier": 10, | ||
"lookup_range": [ | ||
0, | ||
64 | ||
], | ||
"logrows": 7, | ||
"num_inner_cols": 2, | ||
"variables": [ | ||
[ | ||
"batch_size", | ||
1 | ||
] | ||
], | ||
"input_visibility": "Public", | ||
"output_visibility": "Public", | ||
"param_visibility": "Fixed", | ||
"div_rebasing": false, | ||
"rebase_frac_zero_constants": false, | ||
"check_mode": "UNSAFE", | ||
"commitment": "KZG" | ||
}, | ||
"num_rows": 14, | ||
"total_assignments": 28, | ||
"total_const_size": 2, | ||
"total_dynamic_col_size": 0, | ||
"num_dynamic_lookups": 0, | ||
"num_shuffles": 1, | ||
"total_shuffle_col_size": 5, | ||
"model_instance_shapes": [ | ||
[ | ||
1, | ||
5 | ||
], | ||
[ | ||
1 | ||
] | ||
], | ||
"model_output_scales": [ | ||
2 | ||
], | ||
"model_input_scales": [ | ||
2 | ||
], | ||
"module_sizes": { | ||
"polycommit": [], | ||
"poseidon": [ | ||
0, | ||
[ | ||
0 | ||
] | ||
] | ||
}, | ||
"required_lookups": [ | ||
{ | ||
"GreaterThanEqual": { | ||
"a": 0.0 | ||
} | ||
} | ||
], | ||
"required_range_checks": [], | ||
"check_mode": "UNSAFE", | ||
"version": "10.4.2", | ||
"num_blinding_factors": null, | ||
"timestamp": 1715191033368 | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"input_data": [[0.4000000059604645, 2.0, 3.0, 3.0, 4.0]]} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"inputs":[["0200000000000000000000000000000000000000000000000000000000000000","0800000000000000000000000000000000000000000000000000000000000000","0c00000000000000000000000000000000000000000000000000000000000000","0c00000000000000000000000000000000000000000000000000000000000000","1000000000000000000000000000000000000000000000000000000000000000"]],"pretty_elements":{"rescaled_inputs":[["0.5","2","3","3","4"]],"inputs":[["0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000008","0x000000000000000000000000000000000000000000000000000000000000000c","0x000000000000000000000000000000000000000000000000000000000000000c","0x0000000000000000000000000000000000000000000000000000000000000010"]],"processed_inputs":[],"processed_params":[],"processed_outputs":[],"rescaled_outputs":[["4"]],"outputs":[["0x0000000000000000000000000000000000000000000000000000000000000010"]]},"outputs":[["1000000000000000000000000000000000000000000000000000000000000000"]],"processed_inputs":null,"processed_params":null,"processed_outputs":null,"max_lookup_inputs":6,"min_lookup_inputs":0,"max_range_size":0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import ezkl | ||
import os | ||
import argparse | ||
from utils import relative_file_path | ||
import json | ||
import torch | ||
from torch.autograd import Variable | ||
|
||
parser = argparse.ArgumentParser( | ||
prog='Omron AVS ezkl operator engine') | ||
|
||
parser.add_argument('-i','--input', nargs='+', help='input data to run on', required=True) | ||
|
||
args = parser.parse_args() | ||
|
||
input = Variable(torch.Tensor([float(i) for i in args.input])) | ||
|
||
data_array = ((input).detach().numpy()).reshape([-1]).tolist() | ||
|
||
data_path = relative_file_path("proof/inputs.json") | ||
witness_path = relative_file_path("proof/witness.json") | ||
compiled_model_path = relative_file_path("model_data/network.ezkl") | ||
pk_path = relative_file_path("model_data/test.pk") | ||
vk_path = relative_file_path("model_data/test.vk") | ||
settings_path = relative_file_path("model_data/settings.json") | ||
proof_path = relative_file_path('proof/proof.json') | ||
|
||
# Serialize data into file: | ||
data = dict(input_data = [data_array]) | ||
json.dump(data, open(data_path, 'w')) | ||
|
||
# Generate the Witness for the proof | ||
ezkl.gen_witness(data_path, compiled_model_path, witness_path) | ||
|
||
# Generate the proof | ||
proof = ezkl.prove( | ||
witness_path, | ||
compiled_model_path, | ||
pk_path, | ||
proof_path, | ||
"single", | ||
) | ||
assert ezkl.verify( | ||
proof_path, | ||
settings_path, | ||
vk_path, | ||
) == True | ||
|
||
onchain_input_array = [] | ||
|
||
# using a loop | ||
# avoiding printing last comma | ||
formatted_output = "[" | ||
for i, value in enumerate(proof["instances"]): | ||
for j, field_element in enumerate(value): | ||
onchain_input_array.append(ezkl.felt_to_big_endian(field_element)) | ||
formatted_output += '"' + str(onchain_input_array[-1]) + '"' | ||
if j != len(value) - 1: | ||
formatted_output += ", " | ||
if i != len(proof["instances"]) - 1: | ||
formatted_output += ", " | ||
formatted_output += "]" | ||
|
||
# This will be the values you use onchain | ||
# copy them over to remix and see if they verify | ||
# What happens when you change a value? | ||
print("Inputs: ", formatted_output) | ||
print("Proof: ", proof["proof"]) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import ezkl | ||
import os | ||
|
||
vk_path = os.path.join("./model_data/test.vk") | ||
settings_path = os.path.join("./model_data/settings.json") | ||
|
||
sol_code_path = os.path.join('../contracts/src/ZKVerifier.sol') | ||
abi_path = os.path.join('../contracts/abi/ZKVerifier.abi.json') | ||
|
||
print ("INFO: Generating solidity contract") | ||
|
||
res = ezkl.create_evm_verifier( | ||
vk_path, | ||
settings_path, | ||
sol_code_path, | ||
abi_path | ||
) | ||
|
||
print("SUCCESS: Solidity contract generated at", sol_code_path) | ||
print("SUCCESS: Solidity contract abi now at", abi_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import os | ||
|
||
# Makes sure the files will end up in the same place relative to the base python path | ||
def relative_file_path (file_path : str) : | ||
return os.path.join(os.path.dirname(__file__), file_path) |