-
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.
- Loading branch information
1 parent
64f6066
commit 7574e1b
Showing
6 changed files
with
108 additions
and
68 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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
# Tests | ||
|
||
Plume, which is written in sage. Generates test values `r`, `sk` and `msg` 32 bytes long, then runs `nargo check`, fills in the required values in `Prover.toml`, and finally runs the commands `nargo prove` and `nargo verify`. | ||
Plume, which is written in sage. Generates test values `r`, `sk` of 32 bytes and msg of arbitrary length, then runs `nargo check`, fills in the required values in `Prover.toml` and changes the files `main.nr` and `constants.nr`. | ||
|
||
## Build and Run | ||
|
||
1. Install SageMath by following [these instructions](https://doc.sagemath.org/html/en/installation/index.html). | ||
2. To start, select the version of plume you want to test and uncomment the corresponding line in [main.nr](../crates/use/src/main.nr), and comment out the other. | ||
3. Change the MSG_LEN value in the [constants](../crates/plume/src/constants.nr) file to 32. | ||
4. Run test.sage script of the appropriate version using the command `sage test.sage v1` or `sage test.sage v2`. | ||
2. To start, select the version of plume you want to run "v1" or "v2", then the number of bytes for msg (non-negative number). For example, `sage gen_data.sage v2 32`. | ||
|
||
After that, you can run the program without interfering with the Noir code. |
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,97 @@ | ||
import sys | ||
import subprocess | ||
import toml | ||
load('test_gen.sage') | ||
|
||
# Run a shell command and print the output | ||
def run_command(command): | ||
result = subprocess.run(command, shell=True, capture_output=True, text=True) | ||
if result.stdout: | ||
print(result.stdout, end='') | ||
|
||
if result.returncode != 0: | ||
if result.stderr: | ||
print(result.stderr) | ||
raise subprocess.CalledProcessError(result.returncode, command) | ||
|
||
def format_array(arr): | ||
return "[" + ", ".join(f'"{item}"' for item in arr) + "]" | ||
|
||
def format_double_array(pk): | ||
return "[" + ", ".join(format_array(subarr) for subarr in pk) + "]" | ||
|
||
def update_prover_toml(filepath, version1: bool, msg_len: int): | ||
data = toml.load(filepath) | ||
(msg, c, s, pk, nullifier) = plume_generate_test_case(version1, msg_len) | ||
|
||
data['c'] = c | ||
data['msg'] = msg | ||
data['nullifier'] = nullifier | ||
data['pk'] = pk | ||
data['s'] = s | ||
|
||
c_str = format_array(c) | ||
msg_str = format_array(msg) | ||
nullifier_str = format_double_array(nullifier) | ||
pk_str = format_double_array(pk) | ||
s_str = format_array(s) | ||
|
||
with open(filepath, 'w') as f: | ||
f.write(f'c = {c_str}\n') | ||
f.write(f'msg = {msg_str}\n') | ||
f.write(f'nullifier = {nullifier_str}\n') | ||
f.write(f'pk = {pk_str}\n') | ||
f.write(f's = {s_str}\n') | ||
|
||
def update_plume_version(is_v1: bool): | ||
path = "../crates/use/src/" | ||
p1_line = 13 | ||
p2_line = 14 | ||
|
||
with open(path + 'main.nr', 'r') as file: | ||
lines = file.readlines() | ||
|
||
if is_v1: | ||
lines[p1_line] = " plume_v1(msg, c, s, pk, nullifier);\n" | ||
lines[p2_line] = " // plume_v2(msg, c, s, pk, nullifier);\n" | ||
else: | ||
lines[p1_line] = " // plume_v1(msg, c, s, pk, nullifier);\n" | ||
lines[p2_line] = " plume_v2(msg, c, s, pk, nullifier);\n" | ||
|
||
with open(path + 'main.nr', 'w') as file: | ||
file.writelines(lines) | ||
|
||
|
||
def update_MSG_LEN_variable(msg_len: int): | ||
path = "../crates/plume/src/" | ||
with open(path + 'constants.nr', 'r') as file: | ||
lines = file.readlines() | ||
|
||
MSG_LEN_line = 2 | ||
lines[MSG_LEN_line] = lines[MSG_LEN_line][:-4] + str(msg_len) + ";\n" | ||
|
||
with open(path + 'constants.nr', 'w') as file: | ||
file.writelines(lines) | ||
|
||
|
||
# Take MSG_LEN number and plume version (v1 or v2) | ||
if __name__ == "__main__": | ||
run_command("nargo check") | ||
|
||
prover_toml_path = "../crates/use/Prover.toml" | ||
if len(sys.argv) != 3: | ||
print("Error: incorrect number of arguments") | ||
sys.exit() | ||
|
||
versions = ["v1", "v2"] | ||
|
||
if sys.argv[1] not in versions: | ||
print("Error:", sys.argv[1], "incorrect version.") | ||
sys.exit() | ||
|
||
is_v1 = sys.argv[1] == versions[0] | ||
msg_len = int(sys.argv[2]) | ||
|
||
update_plume_version(is_v1) | ||
update_MSG_LEN_variable(msg_len) | ||
update_prover_toml(prover_toml_path, is_v1, msg_len) |
This file was deleted.
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