Skip to content

Commit

Permalink
feat: code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Jan 11, 2023
1 parent 45aec7a commit bae4fcc
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 242 deletions.
2 changes: 1 addition & 1 deletion air-script/tests/aux_trace/aux_trace.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"num_polys": 7,
"num_variables": 18,
"constants": [1, 1, 1, 1, 1],
"constants": [1],
"expressions": [
{"op": "ADD", "lhs": {"type": "POL", "index": 1}, "rhs": {"type": "POL", "index": 2}},
{"op": "SUB", "lhs": {"type": "POL_NEXT", "index": 0}, "rhs": {"type": "EXPR", "index": 0}},
Expand Down
2 changes: 1 addition & 1 deletion air-script/tests/binary/binary.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"num_polys": 2,
"num_variables": 16,
"constants": [0, 2, 0, 2],
"constants": [0, 2],
"expressions": [
{"op": "MUL", "lhs": {"type": "POL", "index": 0}, "rhs": {"type": "POL", "index": 0}},
{"op": "SUB", "lhs": {"type": "EXPR", "index": 0}, "rhs": {"type": "POL", "index": 0}},
Expand Down
12 changes: 6 additions & 6 deletions air-script/tests/constants/constants.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"num_polys": 10,
"num_variables": 32,
"constants": [1, 0, 1, 1, 2, 2, 0],
"constants": [1, 0, 2],
"expressions": [
{"op": "ADD", "lhs": {"type": "POL", "index": 0}, "rhs": {"type": "CONST", "index": 0}},
{"op": "SUB", "lhs": {"type": "POL_NEXT", "index": 0}, "rhs": {"type": "EXPR", "index": 0}},
Expand All @@ -11,14 +11,14 @@
{"op": "MUL", "lhs": {"type": "EXPR", "index": 4}, "rhs": {"type": "POL", "index": 2}},
{"op": "SUB", "lhs": {"type": "POL_NEXT", "index": 2}, "rhs": {"type": "EXPR", "index": 5}},
{"op": "ADD", "lhs": {"type": "POL", "index": 4}, "rhs": {"type": "CONST", "index": 0}},
{"op": "MUL", "lhs": {"type": "CONST", "index": 1}, "rhs": {"type": "CONST", "index": 4}},
{"op": "MUL", "lhs": {"type": "CONST", "index": 1}, "rhs": {"type": "CONST", "index": 2}},
{"op": "ADD", "lhs": {"type": "EXPR", "index": 7}, "rhs": {"type": "EXPR", "index": 8}},
{"op": "SUB", "lhs": {"type": "POL_NEXT", "index": 4}, "rhs": {"type": "EXPR", "index": 9}},
{"op": "MUL", "lhs": {"type": "CONST", "index": 0}, "rhs": {"type": "CONST", "index": 1}},
{"op": "ADD", "lhs": {"type": "CONST", "index": 0}, "rhs": {"type": "EXPR", "index": 11}},
{"op": "SUB", "lhs": {"type": "POL", "index": 4}, "rhs": {"type": "EXPR", "index": 12}},
{"op": "SUB", "lhs": {"type": "POL", "index": 0}, "rhs": {"type": "CONST", "index": 0}},
{"op": "MUL", "lhs": {"type": "CONST", "index": 1}, "rhs": {"type": "CONST", "index": 4}},
{"op": "MUL", "lhs": {"type": "CONST", "index": 1}, "rhs": {"type": "CONST", "index": 2}},
{"op": "ADD", "lhs": {"type": "CONST", "index": 0}, "rhs": {"type": "EXPR", "index": 15}},
{"op": "SUB", "lhs": {"type": "POL", "index": 1}, "rhs": {"type": "EXPR", "index": 16}},
{"op": "SUB", "lhs": {"type": "CONST", "index": 1}, "rhs": {"type": "CONST", "index": 1}},
Expand All @@ -27,11 +27,11 @@
{"op": "ADD", "lhs": {"type": "CONST", "index": 0}, "rhs": {"type": "CONST", "index": 1}},
{"op": "SUB", "lhs": {"type": "EXPR", "index": 21}, "rhs": {"type": "CONST", "index": 0}},
{"op": "ADD", "lhs": {"type": "EXPR", "index": 22}, "rhs": {"type": "CONST", "index": 0}},
{"op": "SUB", "lhs": {"type": "EXPR", "index": 23}, "rhs": {"type": "CONST", "index": 4}},
{"op": "ADD", "lhs": {"type": "EXPR", "index": 24}, "rhs": {"type": "CONST", "index": 4}},
{"op": "SUB", "lhs": {"type": "EXPR", "index": 23}, "rhs": {"type": "CONST", "index": 2}},
{"op": "ADD", "lhs": {"type": "EXPR", "index": 24}, "rhs": {"type": "CONST", "index": 2}},
{"op": "SUB", "lhs": {"type": "EXPR", "index": 25}, "rhs": {"type": "CONST", "index": 1}},
{"op": "SUB", "lhs": {"type": "POL", "index": 3}, "rhs": {"type": "EXPR", "index": 26}},
{"op": "MUL", "lhs": {"type": "CONST", "index": 1}, "rhs": {"type": "CONST", "index": 4}},
{"op": "MUL", "lhs": {"type": "CONST", "index": 1}, "rhs": {"type": "CONST", "index": 2}},
{"op": "ADD", "lhs": {"type": "CONST", "index": 0}, "rhs": {"type": "EXPR", "index": 28}},
{"op": "SUB", "lhs": {"type": "POL", "index": 4}, "rhs": {"type": "EXPR", "index": 29}},
{"op": "MUL", "lhs": {"type": "CONST", "index": 0}, "rhs": {"type": "CONST", "index": 0}},
Expand Down
14 changes: 0 additions & 14 deletions air-script/tests/exponentiation/exponentiation.air

This file was deleted.

20 changes: 0 additions & 20 deletions air-script/tests/exponentiation/generated_exponentiation.json

This file was deleted.

76 changes: 8 additions & 68 deletions air-script/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ fn gce_aux_trace() {
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Failed to read form file");
fs::remove_file(result_file).expect("Failed to remove file");

expected.assert_eq(&contents);

fs::remove_file(result_file).expect("Failed to remove file");
}

#[test]
Expand Down Expand Up @@ -64,9 +65,10 @@ fn gce_binary() {
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Failed to read form file");
fs::remove_file(result_file).expect("Failed to remove file");

expected.assert_eq(&contents);

fs::remove_file(result_file).expect("Failed to remove file");
}

#[test]
Expand All @@ -80,28 +82,6 @@ fn winterfell_periodic_columns() {
expected.assert_eq(&generated_air);
}

// not yet implemented (periodic columns)
#[test]
#[ignore]
fn gce_periodic_columns() {
let test_path = "tests/periodic_columns/periodic_columns";
let result_file = "tests/periodic_columns/generated_periodic_columns.json";

let test = Test::new([test_path, "air"].join("."));
test.generate_gce(2, result_file)
.expect("GCE generation failed");

let expected = expect_file![[test_path, "json"].join(".").trim_start_matches("tests/")];

let mut file = File::open(result_file).expect("Failed to open file");
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Failed to read form file");
fs::remove_file(result_file).expect("Failed to remove file");

expected.assert_eq(&contents);
}

#[test]
fn winterfell_pub_inputs() {
let test = Test::new("tests/pub_inputs/pub_inputs.air".to_string());
Expand All @@ -128,9 +108,10 @@ fn gce_pub_inputs() {
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Failed to read form file");
fs::remove_file(result_file).expect("Failed to remove file");

expected.assert_eq(&contents);

fs::remove_file(result_file).expect("Failed to remove file");
}

#[test]
Expand Down Expand Up @@ -159,9 +140,10 @@ fn gce_system() {
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Failed to read form file");
fs::remove_file(result_file).expect("Failed to remove file");

expected.assert_eq(&contents);

fs::remove_file(result_file).expect("Failed to remove file");
}

#[test]
Expand All @@ -175,28 +157,6 @@ fn winterfell_bitwise() {
expected.assert_eq(&generated_air);
}

// not yet implemented (periodic columns)
#[test]
#[ignore]
fn gce_bitwise() {
let test_path = "tests/bitwise/bitwise";
let result_file = "tests/bitwise/generated_bitwise.json";

let test = Test::new([test_path, "air"].join("."));
test.generate_gce(2, result_file)
.expect("GCE generation failed");

let expected = expect_file![[test_path, "json"].join(".").trim_start_matches("tests/")];

let mut file = File::open(result_file).expect("Failed to open file");
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Failed to read form file");
fs::remove_file(result_file).expect("Failed to remove file");

expected.assert_eq(&contents);
}

#[test]
fn winterfell_constants() {
let test = Test::new("tests/constants/constants.air".to_string());
Expand All @@ -223,30 +183,10 @@ fn gce_constants() {
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Failed to read form file");
fs::remove_file(result_file).expect("Failed to remove file");

expected.assert_eq(&contents);
}

#[test]
#[ignore] // exponentiation for boundary constraints is not ready
fn gce_exponentiation() {
let test_path = "tests/exponentiation/exponentiation";
let result_file = "tests/exponentiation/generated_exponentiation.json";

let test = Test::new([test_path, "air"].join("."));
test.generate_gce(2, result_file)
.expect("GCE generation failed");

let expected = expect_file![[test_path, "json"].join(".").trim_start_matches("tests/")];

let mut file = File::open(result_file).expect("Failed to open file");
let mut contents = String::new();
file.read_to_string(&mut contents)
.expect("Failed to read form file");
fs::remove_file(result_file).expect("Failed to remove file");

expected.assert_eq(&contents);
}

#[test]
Expand Down
Loading

0 comments on commit bae4fcc

Please sign in to comment.