From 94350e89b2ad076047cb51b6ab51e17ad54b556c Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Tue, 4 Nov 2025 16:42:25 +0100 Subject: [PATCH 01/22] feat: target latest commit on 0xMiden/Plonky3 main branch --- air-script/Cargo.toml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/air-script/Cargo.toml b/air-script/Cargo.toml index 50ec896f2..25a265f82 100644 --- a/air-script/Cargo.toml +++ b/air-script/Cargo.toml @@ -30,18 +30,18 @@ mir = { package = "air-mir", path = "../mir", version = "0.5" } [dev-dependencies] expect-test = "1.4" -p3-air = { package = "p3-air", version = "0.3", default-features = false } -p3-challenger = { package = "p3-challenger", version = "0.3", default-features = false } -p3-circle = { package = "p3-circle", version = "0.3", default-features = false } -p3-commit = { package = "p3-commit", version = "0.3", default-features = false } -p3-field = { package = "p3-field", version = "0.3", default-features = false } -p3-fri = { package = "p3-fri", version = "0.3", default-features = false } -p3-matrix = { package = "p3-matrix", version = "0.3", default-features = false } -p3-merkle-tree = { package = "p3-merkle-tree", version = "0.3", default-features = false } -p3-goldilocks = { package = "p3-goldilocks", version = "0.3", default-features = false } -p3-sha256 = { package = "p3-sha256", version = "0.3", default-features = false } -p3-symmetric = { package = "p3-symmetric", version = "0.3", default-features = false } -p3-uni-stark = { package = "p3-uni-stark", version = "0.3.0", default-features = false } +p3-air = { package = "p3-air", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-challenger = { package = "p3-challenger", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-circle = { package = "p3-circle", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-commit = { package = "p3-commit", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-field = { package = "p3-field", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-fri = { package = "p3-fri", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-matrix = { package = "p3-matrix", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-merkle-tree = { package = "p3-merkle-tree", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-goldilocks = { package = "p3-goldilocks", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-sha256 = { package = "p3-sha256", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-symmetric = { package = "p3-symmetric", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } +p3-uni-stark = { package = "p3-uni-stark", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } winter-air = { package = "winter-air", version = "0.12", default-features = false } winter-math = { package = "winter-math", version = "0.12", default-features = false } winter-utils = { package = "winter-utils", version = "0.12", default-features = false } From 69626ddc07436f31dd6461c56c84848e6e9ba3d9 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Tue, 4 Nov 2025 16:43:13 +0100 Subject: [PATCH 02/22] fix: AirBuilder::Var is now Clone, not Copy --- air-script/tests/binary/binary_plonky3.rs | 6 ++-- air-script/tests/bitwise/bitwise_plonky3.rs | 36 +++++++++---------- .../tests/buses/buses_complex_plonky3.rs | 6 ++-- .../computed_indices_complex_plonky3.rs | 4 +-- .../computed_indices_simple_plonky3.rs | 18 +++++----- .../constant_in_range_plonky3.rs | 4 +-- .../tests/constants/constants_plonky3.rs | 22 ++++++------ .../constraint_comprehension_plonky3.rs | 10 +++--- .../tests/evaluators/evaluators_plonky3.rs | 22 ++++++------ .../tests/fibonacci/fibonacci_plonky3.rs | 10 +++--- .../functions/functions_complex_plonky3.rs | 6 ++-- .../functions/functions_simple_plonky3.rs | 18 +++++----- .../indexed_trace_access_plonky3.rs | 4 +-- .../list_comprehension_nested_plonky3.rs | 8 ++--- .../list_comprehension_plonky3.rs | 14 ++++---- .../list_folding/list_folding_plonky3.rs | 10 +++--- .../periodic_columns_plonky3.rs | 6 ++-- .../tests/pub_inputs/pub_inputs_plonky3.rs | 18 +++++----- .../selectors_combine_complex_plonky3.rs | 8 ++--- .../selectors_combine_simple_plonky3.rs | 6 ++-- ...ombine_with_list_comprehensions_plonky3.rs | 8 ++--- .../tests/selectors/selectors_plonky3.rs | 6 ++-- .../selectors_with_evaluators_plonky3.rs | 6 ++-- air-script/tests/system/system_plonky3.rs | 4 +-- .../trace_col_groups_plonky3.rs | 6 ++-- .../tests/variables/variables_plonky3.rs | 12 +++---- codegen/plonky3/src/air/graph.rs | 4 +-- 27 files changed, 141 insertions(+), 141 deletions(-) diff --git a/air-script/tests/binary/binary_plonky3.rs b/air-script/tests/binary/binary_plonky3.rs index df44bcb6d..95f14d739 100644 --- a/air-script/tests/binary/binary_plonky3.rs +++ b/air-script/tests/binary/binary_plonky3.rs @@ -37,8 +37,8 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into() - public_values[0].into()); - builder.assert_zero::<_>(main_current[0].into() * main_current[0].into() - main_current[0].into()); - builder.assert_zero::<_>(main_current[1].into() * main_current[1].into() - main_current[1].into()); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into() - public_values[0].into()); + builder.assert_zero::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.assert_zero::<_>(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); } } \ No newline at end of file diff --git a/air-script/tests/bitwise/bitwise_plonky3.rs b/air-script/tests/bitwise/bitwise_plonky3.rs index ef5d5d992..2c58d50e2 100644 --- a/air-script/tests/bitwise/bitwise_plonky3.rs +++ b/air-script/tests/bitwise/bitwise_plonky3.rs @@ -39,23 +39,23 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[13].into()); - builder.assert_zero::<_>(main_current[0].into() * main_current[0].into() - main_current[0].into()); - builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[0].into() - main_current[0].into())); - builder.assert_zero::<_>(main_current[3].into() * main_current[3].into() - main_current[3].into()); - builder.assert_zero::<_>(main_current[4].into() * main_current[4].into() - main_current[4].into()); - builder.assert_zero::<_>(main_current[5].into() * main_current[5].into() - main_current[5].into()); - builder.assert_zero::<_>(main_current[6].into() * main_current[6].into() - main_current[6].into()); - builder.assert_zero::<_>(main_current[7].into() * main_current[7].into() - main_current[7].into()); - builder.assert_zero::<_>(main_current[8].into() * main_current[8].into() - main_current[8].into()); - builder.assert_zero::<_>(main_current[9].into() * main_current[9].into() - main_current[9].into()); - builder.assert_zero::<_>(main_current[10].into() * main_current[10].into() - main_current[10].into()); - builder.assert_zero::<_>(periodic_values[0].into() * (main_current[1].into() - (main_current[3].into() + main_current[4].into().double() + AB::Expr::from_u64(4) * main_current[5].into() + AB::Expr::from_u64(8) * main_current[6].into()))); - builder.assert_zero::<_>(periodic_values[0].into() * (main_current[2].into() - (main_current[7].into() + main_current[8].into().double() + AB::Expr::from_u64(4) * main_current[9].into() + AB::Expr::from_u64(8) * main_current[10].into()))); - builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[1].into() - (main_current[1].into() * AB::Expr::from_u64(16) + main_current[3].into() + main_current[4].into().double() + AB::Expr::from_u64(4) * main_current[5].into() + AB::Expr::from_u64(8) * main_current[6].into()))); - builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[2].into() - (main_current[2].into() * AB::Expr::from_u64(16) + main_current[7].into() + main_current[8].into().double() + AB::Expr::from_u64(4) * main_current[9].into() + AB::Expr::from_u64(8) * main_current[10].into()))); - builder.assert_zero::<_>(periodic_values[0].into() * main_current[11].into()); - builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_current[12].into() - main_next[11].into())); - builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].into()) * (main_current[12].into() - (main_current[11].into() * AB::Expr::from_u64(16) + main_current[3].into() * main_current[7].into() + main_current[4].into().double() * main_current[8].into() + AB::Expr::from_u64(4) * main_current[5].into() * main_current[9].into() + AB::Expr::from_u64(8) * main_current[6].into() * main_current[10].into())) + main_current[0].into() * (main_current[12].into() - (main_current[11].into() * AB::Expr::from_u64(16) + main_current[3].into() + main_current[7].into() - main_current[3].into().double() * main_current[7].into() + (main_current[4].into() + main_current[8].into() - main_current[4].into().double() * main_current[8].into()).double() + AB::Expr::from_u64(4) * (main_current[5].into() + main_current[9].into() - main_current[5].into().double() * main_current[9].into()) + AB::Expr::from_u64(8) * (main_current[6].into() + main_current[10].into() - main_current[6].into().double() * main_current[10].into())))); + builder.when_first_row().assert_zero::<_>(main_current[13].clone().into()); + builder.assert_zero::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[0].clone().into() - main_current[0].clone().into())); + builder.assert_zero::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); + builder.assert_zero::<_>(main_current[4].clone().into() * main_current[4].clone().into() - main_current[4].clone().into()); + builder.assert_zero::<_>(main_current[5].clone().into() * main_current[5].clone().into() - main_current[5].clone().into()); + builder.assert_zero::<_>(main_current[6].clone().into() * main_current[6].clone().into() - main_current[6].clone().into()); + builder.assert_zero::<_>(main_current[7].clone().into() * main_current[7].clone().into() - main_current[7].clone().into()); + builder.assert_zero::<_>(main_current[8].clone().into() * main_current[8].clone().into() - main_current[8].clone().into()); + builder.assert_zero::<_>(main_current[9].clone().into() * main_current[9].clone().into() - main_current[9].clone().into()); + builder.assert_zero::<_>(main_current[10].clone().into() * main_current[10].clone().into() - main_current[10].clone().into()); + builder.assert_zero::<_>(periodic_values[0].into() * (main_current[1].clone().into() - (main_current[3].clone().into() + main_current[4].clone().into().double() + AB::Expr::from_u64(4) * main_current[5].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into()))); + builder.assert_zero::<_>(periodic_values[0].into() * (main_current[2].clone().into() - (main_current[7].clone().into() + main_current[8].clone().into().double() + AB::Expr::from_u64(4) * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[10].clone().into()))); + builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[1].clone().into() - (main_current[1].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[4].clone().into().double() + AB::Expr::from_u64(4) * main_current[5].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into()))); + builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[2].clone().into() - (main_current[2].clone().into() * AB::Expr::from_u64(16) + main_current[7].clone().into() + main_current[8].clone().into().double() + AB::Expr::from_u64(4) * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[10].clone().into()))); + builder.assert_zero::<_>(periodic_values[0].into() * main_current[11].clone().into()); + builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_current[12].clone().into() - main_next[11].clone().into())); + builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() * main_current[7].clone().into() + main_current[4].clone().into().double() * main_current[8].clone().into() + AB::Expr::from_u64(4) * main_current[5].clone().into() * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into() * main_current[10].clone().into())) + main_current[0].clone().into() * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[7].clone().into() - main_current[3].clone().into().double() * main_current[7].clone().into() + (main_current[4].clone().into() + main_current[8].clone().into() - main_current[4].clone().into().double() * main_current[8].clone().into()).double() + AB::Expr::from_u64(4) * (main_current[5].clone().into() + main_current[9].clone().into() - main_current[5].clone().into().double() * main_current[9].clone().into()) + AB::Expr::from_u64(8) * (main_current[6].clone().into() + main_current[10].clone().into() - main_current[6].clone().into().double() * main_current[10].clone().into())))); } } \ No newline at end of file diff --git a/air-script/tests/buses/buses_complex_plonky3.rs b/air-script/tests/buses/buses_complex_plonky3.rs index 462ef499a..ef56d20b3 100644 --- a/air-script/tests/buses/buses_complex_plonky3.rs +++ b/air-script/tests/buses/buses_complex_plonky3.rs @@ -37,8 +37,8 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into()); - builder.assert_zero::<_>(main_current[2].into() * main_current[2].into() - main_current[2].into()); - builder.assert_zero::<_>(main_current[3].into() * main_current[3].into() - main_current[3].into()); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); + builder.assert_zero::<_>(main_current[2].clone().into() * main_current[2].clone().into() - main_current[2].clone().into()); + builder.assert_zero::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); } } \ No newline at end of file diff --git a/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs b/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs index 1ded2a430..099828dc5 100644 --- a/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs +++ b/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs @@ -37,7 +37,7 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into()); - builder.assert_zero::<_>(main_current[2].into() * AB::Expr::from_u64(3) + main_current[3].into() * AB::Expr::from_u64(4)); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); + builder.assert_zero::<_>(main_current[2].clone().into() * AB::Expr::from_u64(3) + main_current[3].clone().into() * AB::Expr::from_u64(4)); } } \ No newline at end of file diff --git a/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs b/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs index 3ac8ed33b..8e821b4a8 100644 --- a/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs +++ b/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs @@ -37,14 +37,14 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into()); - builder.assert_zero::<_>(main_current[0].into()); - builder.assert_zero::<_>(main_current[1].into() - AB::Expr::from_u64(2)); - builder.assert_zero::<_>(main_current[2].into() - AB::Expr::from_u64(4)); - builder.assert_zero::<_>(main_current[3].into() - AB::Expr::from_u64(6)); - builder.when_transition().assert_zero::<_>(main_next[4].into()); - builder.when_transition().assert_zero::<_>(main_next[5].into() - main_current[5].into().double()); - builder.when_transition().assert_zero::<_>(main_next[6].into() - AB::Expr::from_u64(6) * main_current[6].into()); - builder.when_transition().assert_zero::<_>(main_next[7].into() - AB::Expr::from_u64(12) * main_current[7].into()); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); + builder.assert_zero::<_>(main_current[0].clone().into()); + builder.assert_zero::<_>(main_current[1].clone().into() - AB::Expr::from_u64(2)); + builder.assert_zero::<_>(main_current[2].clone().into() - AB::Expr::from_u64(4)); + builder.assert_zero::<_>(main_current[3].clone().into() - AB::Expr::from_u64(6)); + builder.when_transition().assert_zero::<_>(main_next[4].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[5].clone().into() - main_current[5].clone().into().double()); + builder.when_transition().assert_zero::<_>(main_next[6].clone().into() - AB::Expr::from_u64(6) * main_current[6].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[7].clone().into() - AB::Expr::from_u64(12) * main_current[7].clone().into()); } } \ No newline at end of file diff --git a/air-script/tests/constant_in_range/constant_in_range_plonky3.rs b/air-script/tests/constant_in_range/constant_in_range_plonky3.rs index 5f657e987..88013d4f3 100644 --- a/air-script/tests/constant_in_range/constant_in_range_plonky3.rs +++ b/air-script/tests/constant_in_range/constant_in_range_plonky3.rs @@ -37,7 +37,7 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[6].into()); - builder.assert_zero::<_>(main_current[0].into() - (main_current[1].into() - main_current[4].into() - main_current[8].into() + AB::Expr::ONE + main_current[2].into() - main_current[5].into() - main_current[9].into() + AB::Expr::from_u64(2) + main_current[3].into() - main_current[6].into() - main_current[10].into())); + builder.when_first_row().assert_zero::<_>(main_current[6].clone().into()); + builder.assert_zero::<_>(main_current[0].clone().into() - (main_current[1].clone().into() - main_current[4].clone().into() - main_current[8].clone().into() + AB::Expr::ONE + main_current[2].clone().into() - main_current[5].clone().into() - main_current[9].clone().into() + AB::Expr::from_u64(2) + main_current[3].clone().into() - main_current[6].clone().into() - main_current[10].clone().into())); } } \ No newline at end of file diff --git a/air-script/tests/constants/constants_plonky3.rs b/air-script/tests/constants/constants_plonky3.rs index fa2ffccac..ee2300915 100644 --- a/air-script/tests/constants/constants_plonky3.rs +++ b/air-script/tests/constants/constants_plonky3.rs @@ -37,16 +37,16 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into() - AB::Expr::ONE); - builder.when_first_row().assert_zero::<_>(main_current[1].into() - AB::Expr::ONE); - builder.when_first_row().assert_zero::<_>(main_current[2].into()); - builder.when_first_row().assert_zero::<_>(main_current[3].into() - AB::Expr::ONE); - builder.when_first_row().assert_zero::<_>(main_current[4].into() - AB::Expr::ONE); - builder.when_last_row().assert_zero::<_>(main_current[6].into()); - builder.when_transition().assert_zero::<_>(main_next[0].into() - (main_current[0].into() + AB::Expr::ONE)); - builder.when_transition().assert_zero::<_>(main_next[1].into()); - builder.when_transition().assert_zero::<_>(main_next[2].into() - main_current[2].into()); - builder.when_transition().assert_zero::<_>(main_next[5].into() - (main_current[5].into() + AB::Expr::ONE)); - builder.assert_zero::<_>(main_current[4].into() - AB::Expr::ONE); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into() - AB::Expr::ONE); + builder.when_first_row().assert_zero::<_>(main_current[1].clone().into() - AB::Expr::ONE); + builder.when_first_row().assert_zero::<_>(main_current[2].clone().into()); + builder.when_first_row().assert_zero::<_>(main_current[3].clone().into() - AB::Expr::ONE); + builder.when_first_row().assert_zero::<_>(main_current[4].clone().into() - AB::Expr::ONE); + builder.when_last_row().assert_zero::<_>(main_current[6].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); + builder.when_transition().assert_zero::<_>(main_next[1].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[2].clone().into() - main_current[2].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[5].clone().into() - (main_current[5].clone().into() + AB::Expr::ONE)); + builder.assert_zero::<_>(main_current[4].clone().into() - AB::Expr::ONE); } } \ No newline at end of file diff --git a/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs b/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs index b501fe9d3..a79f98584 100644 --- a/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs +++ b/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs @@ -37,10 +37,10 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[8].into()); - builder.assert_zero::<_>(main_current[6].into() - main_current[10].into()); - builder.assert_zero::<_>(main_current[7].into() - main_current[11].into()); - builder.assert_zero::<_>(main_current[8].into() - main_current[12].into()); - builder.assert_zero::<_>(main_current[9].into() - main_current[13].into()); + builder.when_first_row().assert_zero::<_>(main_current[8].clone().into()); + builder.assert_zero::<_>(main_current[6].clone().into() - main_current[10].clone().into()); + builder.assert_zero::<_>(main_current[7].clone().into() - main_current[11].clone().into()); + builder.assert_zero::<_>(main_current[8].clone().into() - main_current[12].clone().into()); + builder.assert_zero::<_>(main_current[9].clone().into() - main_current[13].clone().into()); } } \ No newline at end of file diff --git a/air-script/tests/evaluators/evaluators_plonky3.rs b/air-script/tests/evaluators/evaluators_plonky3.rs index becb57b5a..0a3e2329f 100644 --- a/air-script/tests/evaluators/evaluators_plonky3.rs +++ b/air-script/tests/evaluators/evaluators_plonky3.rs @@ -37,16 +37,16 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into()); - builder.when_transition().assert_zero::<_>(main_next[0].into() - main_current[0].into()); - builder.when_transition().assert_zero::<_>(main_next[2].into() - main_current[2].into()); - builder.when_transition().assert_zero::<_>(main_next[6].into() - main_current[6].into()); - builder.assert_zero::<_>(main_current[0].into() * main_current[0].into() - main_current[0].into()); - builder.assert_zero::<_>(main_current[1].into() * main_current[1].into() - main_current[1].into()); - builder.assert_zero::<_>(main_current[2].into() * main_current[2].into() - main_current[2].into()); - builder.assert_zero::<_>(main_current[3].into() * main_current[3].into() - main_current[3].into()); - builder.assert_zero::<_>(main_current[4].into()); - builder.assert_zero::<_>(main_current[5].into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[6].into() - AB::Expr::from_u64(4)); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - main_current[0].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[2].clone().into() - main_current[2].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[6].clone().into() - main_current[6].clone().into()); + builder.assert_zero::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.assert_zero::<_>(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); + builder.assert_zero::<_>(main_current[2].clone().into() * main_current[2].clone().into() - main_current[2].clone().into()); + builder.assert_zero::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); + builder.assert_zero::<_>(main_current[4].clone().into()); + builder.assert_zero::<_>(main_current[5].clone().into() - AB::Expr::ONE); + builder.assert_zero::<_>(main_current[6].clone().into() - AB::Expr::from_u64(4)); } } \ No newline at end of file diff --git a/air-script/tests/fibonacci/fibonacci_plonky3.rs b/air-script/tests/fibonacci/fibonacci_plonky3.rs index 262dbb610..ec88598e1 100644 --- a/air-script/tests/fibonacci/fibonacci_plonky3.rs +++ b/air-script/tests/fibonacci/fibonacci_plonky3.rs @@ -37,10 +37,10 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into() - public_values[0].into()); - builder.when_first_row().assert_zero::<_>(main_current[1].into() - public_values[1].into()); - builder.when_last_row().assert_zero::<_>(main_current[1].into() - public_values[2].into()); - builder.when_transition().assert_zero::<_>(main_next[1].into() - (main_current[0].into() + main_current[1].into())); - builder.when_transition().assert_zero::<_>(main_next[0].into() - main_current[1].into()); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into() - public_values[0].into()); + builder.when_first_row().assert_zero::<_>(main_current[1].clone().into() - public_values[1].into()); + builder.when_last_row().assert_zero::<_>(main_current[1].clone().into() - public_values[2].into()); + builder.when_transition().assert_zero::<_>(main_next[1].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())); + builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - main_current[1].clone().into()); } } \ No newline at end of file diff --git a/air-script/tests/functions/functions_complex_plonky3.rs b/air-script/tests/functions/functions_complex_plonky3.rs index cca15366b..6005f5123 100644 --- a/air-script/tests/functions/functions_complex_plonky3.rs +++ b/air-script/tests/functions/functions_complex_plonky3.rs @@ -37,8 +37,8 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[3].into()); - builder.when_transition().assert_zero::<_>(main_next[16].into() - main_current[16].into() * ((main_current[3].into() * main_current[3].into() * main_current[3].into() * main_current[3].into() * main_current[3].into() * main_current[3].into() * main_current[3].into() * main_current[1].into() * main_current[2].into() + main_current[3].into() * main_current[3].into() * (AB::Expr::ONE - main_current[1].into()) * main_current[2].into() + main_current[3].into() * main_current[1].into() * (AB::Expr::ONE - main_current[2].into()) + (AB::Expr::ONE - main_current[1].into()) * (AB::Expr::ONE - main_current[2].into())) * main_current[0].into() - main_current[0].into() + AB::Expr::ONE)); - builder.when_transition().assert_zero::<_>(main_next[3].into() - (main_current[4].into() + main_current[5].into() + main_current[6].into() + main_current[7].into() + main_current[8].into() + main_current[9].into() + main_current[10].into() + main_current[11].into() + main_current[12].into() + main_current[13].into() + main_current[14].into() + main_current[15].into() + AB::Expr::ONE).double()); + builder.when_first_row().assert_zero::<_>(main_current[3].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[16].clone().into() - main_current[16].clone().into() * ((main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() + main_current[3].clone().into() * main_current[3].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_current[2].clone().into() + main_current[3].clone().into() * main_current[1].clone().into() * (AB::Expr::ONE - main_current[2].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into())) * main_current[0].clone().into() - main_current[0].clone().into() + AB::Expr::ONE)); + builder.when_transition().assert_zero::<_>(main_next[3].clone().into() - (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() + main_current[8].clone().into() + main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() + main_current[14].clone().into() + main_current[15].clone().into() + AB::Expr::ONE).double()); } } \ No newline at end of file diff --git a/air-script/tests/functions/functions_simple_plonky3.rs b/air-script/tests/functions/functions_simple_plonky3.rs index 7d19e8a4b..4ea30b778 100644 --- a/air-script/tests/functions/functions_simple_plonky3.rs +++ b/air-script/tests/functions/functions_simple_plonky3.rs @@ -37,14 +37,14 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[3].into()); - builder.assert_zero::<_>(main_current[0].into() * main_current[3].into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[4].into() * main_current[5].into() * main_current[6].into() * main_current[7].into() * main_current[3].into() - AB::Expr::ONE); - builder.assert_zero::<_>((main_current[4].into() + main_current[5].into() + main_current[6].into() + main_current[7].into()) * main_current[4].into() * main_current[5].into() * main_current[6].into() * main_current[7].into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[4].into() * main_current[5].into() * main_current[6].into() * main_current[7].into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[0].into() * main_current[4].into() * main_current[5].into() * main_current[6].into() * main_current[7].into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[1].into() + (main_current[4].into() + main_current[5].into() + main_current[6].into() + main_current[7].into()) * main_current[4].into() * main_current[5].into() * main_current[6].into() * main_current[7].into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[4].into() + main_current[5].into() + main_current[6].into() + main_current[7].into() - AB::Expr::ONE); - builder.assert_zero::<_>((main_current[4].into() + main_current[5].into() + main_current[6].into() + main_current[7].into()) * AB::Expr::from_u64(4) - AB::Expr::ONE); + builder.when_first_row().assert_zero::<_>(main_current[3].clone().into()); + builder.assert_zero::<_>(main_current[0].clone().into() * main_current[3].clone().into() - AB::Expr::ONE); + builder.assert_zero::<_>(main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() * main_current[3].clone().into() - AB::Expr::ONE); + builder.assert_zero::<_>((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero::<_>(main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero::<_>(main_current[0].clone().into() * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero::<_>(main_current[1].clone().into() + (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero::<_>(main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero::<_>((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * AB::Expr::from_u64(4) - AB::Expr::ONE); } } \ No newline at end of file diff --git a/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs b/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs index 0bd768900..c1026ca47 100644 --- a/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs +++ b/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs @@ -37,7 +37,7 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into()); - builder.when_transition().assert_zero::<_>(main_next[0].into() - (main_current[1].into() + AB::Expr::ONE)); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - (main_current[1].clone().into() + AB::Expr::ONE)); } } \ No newline at end of file diff --git a/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs b/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs index 2a8b9181f..02c938d1e 100644 --- a/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs +++ b/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs @@ -37,9 +37,9 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into()); - builder.assert_zero::<_>(main_current[0].into() + main_current[1].into().double() - AB::Expr::from_u64(3)); - builder.assert_zero::<_>(main_current[0].into().double() + main_current[1].into() * AB::Expr::from_u64(3) - AB::Expr::from_u64(5)); - builder.assert_zero::<_>(main_current[0].into() * AB::Expr::from_u64(3) + main_current[1].into() * AB::Expr::from_u64(4) - AB::Expr::from_u64(7)); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); + builder.assert_zero::<_>(main_current[0].clone().into() + main_current[1].clone().into().double() - AB::Expr::from_u64(3)); + builder.assert_zero::<_>(main_current[0].clone().into().double() + main_current[1].clone().into() * AB::Expr::from_u64(3) - AB::Expr::from_u64(5)); + builder.assert_zero::<_>(main_current[0].clone().into() * AB::Expr::from_u64(3) + main_current[1].clone().into() * AB::Expr::from_u64(4) - AB::Expr::from_u64(7)); } } \ No newline at end of file diff --git a/air-script/tests/list_comprehension/list_comprehension_plonky3.rs b/air-script/tests/list_comprehension/list_comprehension_plonky3.rs index b2133e873..9456c4066 100644 --- a/air-script/tests/list_comprehension/list_comprehension_plonky3.rs +++ b/air-script/tests/list_comprehension/list_comprehension_plonky3.rs @@ -37,12 +37,12 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[10].into()); - builder.assert_zero::<_>(main_current[0].into() - main_current[2].into()); - builder.assert_zero::<_>(main_current[4].into() - main_current[0].into() * AB::Expr::from_u64(8) * main_current[11].into()); - builder.when_transition().assert_zero::<_>(main_current[4].into() - main_current[0].into() * (main_next[8].into() - main_next[12].into())); - builder.assert_zero::<_>(main_current[6].into() - main_current[0].into() * (main_current[9].into() - main_current[14].into())); - builder.assert_zero::<_>(main_current[1].into() - (main_current[5].into() - main_current[8].into() - main_current[12].into() + AB::Expr::from_u64(10) + main_current[6].into() - main_current[9].into() - main_current[13].into() + AB::Expr::from_u64(20) + main_current[7].into() - main_current[10].into() - main_current[14].into())); - builder.assert_zero::<_>(main_current[14].into() - AB::Expr::from_u64(10)); + builder.when_first_row().assert_zero::<_>(main_current[10].clone().into()); + builder.assert_zero::<_>(main_current[0].clone().into() - main_current[2].clone().into()); + builder.assert_zero::<_>(main_current[4].clone().into() - main_current[0].clone().into() * AB::Expr::from_u64(8) * main_current[11].clone().into()); + builder.when_transition().assert_zero::<_>(main_current[4].clone().into() - main_current[0].clone().into() * (main_next[8].clone().into() - main_next[12].clone().into())); + builder.assert_zero::<_>(main_current[6].clone().into() - main_current[0].clone().into() * (main_current[9].clone().into() - main_current[14].clone().into())); + builder.assert_zero::<_>(main_current[1].clone().into() - (main_current[5].clone().into() - main_current[8].clone().into() - main_current[12].clone().into() + AB::Expr::from_u64(10) + main_current[6].clone().into() - main_current[9].clone().into() - main_current[13].clone().into() + AB::Expr::from_u64(20) + main_current[7].clone().into() - main_current[10].clone().into() - main_current[14].clone().into())); + builder.assert_zero::<_>(main_current[14].clone().into() - AB::Expr::from_u64(10)); } } \ No newline at end of file diff --git a/air-script/tests/list_folding/list_folding_plonky3.rs b/air-script/tests/list_folding/list_folding_plonky3.rs index c1cd5e912..48538e7e3 100644 --- a/air-script/tests/list_folding/list_folding_plonky3.rs +++ b/air-script/tests/list_folding/list_folding_plonky3.rs @@ -37,10 +37,10 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[11].into()); - builder.when_transition().assert_zero::<_>(main_next[5].into() - (main_current[9].into() + main_current[10].into() + main_current[11].into() + main_current[12].into() + main_current[13].into() * main_current[14].into() * main_current[15].into() * main_current[16].into())); - builder.when_transition().assert_zero::<_>(main_next[6].into() - (main_current[9].into() + main_current[10].into() + main_current[11].into() + main_current[12].into() + main_current[13].into() * main_current[14].into() * main_current[15].into() * main_current[16].into())); - builder.when_transition().assert_zero::<_>(main_next[7].into() - (main_current[9].into() * main_current[13].into() + main_current[10].into() * main_current[14].into() + main_current[11].into() * main_current[15].into() + main_current[12].into() * main_current[16].into() + (main_current[9].into() + main_current[13].into()) * (main_current[10].into() + main_current[14].into()) * (main_current[11].into() + main_current[15].into()) * (main_current[12].into() + main_current[16].into()))); - builder.when_transition().assert_zero::<_>(main_next[8].into() - (main_current[1].into() + main_current[9].into() * main_current[13].into() + main_current[10].into() * main_current[14].into() + main_current[11].into() * main_current[15].into() + main_current[12].into() * main_current[16].into() + main_current[9].into() * main_current[13].into() + main_current[10].into() * main_current[14].into() + main_current[11].into() * main_current[15].into() + main_current[12].into() * main_current[16].into())); + builder.when_first_row().assert_zero::<_>(main_current[11].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[5].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); + builder.when_transition().assert_zero::<_>(main_next[6].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); + builder.when_transition().assert_zero::<_>(main_next[7].clone().into() - (main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + (main_current[9].clone().into() + main_current[13].clone().into()) * (main_current[10].clone().into() + main_current[14].clone().into()) * (main_current[11].clone().into() + main_current[15].clone().into()) * (main_current[12].clone().into() + main_current[16].clone().into()))); + builder.when_transition().assert_zero::<_>(main_next[8].clone().into() - (main_current[1].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into())); } } \ No newline at end of file diff --git a/air-script/tests/periodic_columns/periodic_columns_plonky3.rs b/air-script/tests/periodic_columns/periodic_columns_plonky3.rs index fb42592e1..953454085 100644 --- a/air-script/tests/periodic_columns/periodic_columns_plonky3.rs +++ b/air-script/tests/periodic_columns/periodic_columns_plonky3.rs @@ -39,8 +39,8 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into()); - builder.assert_zero::<_>(periodic_values[0].into() * (main_current[1].into() + main_current[2].into())); - builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[0].into() - main_current[0].into())); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); + builder.assert_zero::<_>(periodic_values[0].into() * (main_current[1].clone().into() + main_current[2].clone().into())); + builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[0].clone().into() - main_current[0].clone().into())); } } \ No newline at end of file diff --git a/air-script/tests/pub_inputs/pub_inputs_plonky3.rs b/air-script/tests/pub_inputs/pub_inputs_plonky3.rs index cb2ac03b7..1c0829516 100644 --- a/air-script/tests/pub_inputs/pub_inputs_plonky3.rs +++ b/air-script/tests/pub_inputs/pub_inputs_plonky3.rs @@ -37,14 +37,14 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into() - public_values[8].into()); - builder.when_first_row().assert_zero::<_>(main_current[1].into() - public_values[9].into()); - builder.when_first_row().assert_zero::<_>(main_current[2].into() - public_values[10].into()); - builder.when_first_row().assert_zero::<_>(main_current[3].into() - public_values[11].into()); - builder.when_last_row().assert_zero::<_>(main_current[0].into() - public_values[12].into()); - builder.when_last_row().assert_zero::<_>(main_current[1].into() - public_values[13].into()); - builder.when_last_row().assert_zero::<_>(main_current[2].into() - public_values[14].into()); - builder.when_last_row().assert_zero::<_>(main_current[3].into() - public_values[15].into()); - builder.when_transition().assert_zero::<_>(main_next[0].into() - (main_current[1].into() + main_current[2].into())); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into() - public_values[8].into()); + builder.when_first_row().assert_zero::<_>(main_current[1].clone().into() - public_values[9].into()); + builder.when_first_row().assert_zero::<_>(main_current[2].clone().into() - public_values[10].into()); + builder.when_first_row().assert_zero::<_>(main_current[3].clone().into() - public_values[11].into()); + builder.when_last_row().assert_zero::<_>(main_current[0].clone().into() - public_values[12].into()); + builder.when_last_row().assert_zero::<_>(main_current[1].clone().into() - public_values[13].into()); + builder.when_last_row().assert_zero::<_>(main_current[2].clone().into() - public_values[14].into()); + builder.when_last_row().assert_zero::<_>(main_current[3].clone().into() - public_values[15].into()); + builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - (main_current[1].clone().into() + main_current[2].clone().into())); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_combine_complex_plonky3.rs b/air-script/tests/selectors/selectors_combine_complex_plonky3.rs index c8115936b..fee0da529 100644 --- a/air-script/tests/selectors/selectors_combine_complex_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_complex_plonky3.rs @@ -37,9 +37,9 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[5].into()); - builder.assert_zero::<_>((main_current[0].into() + (AB::Expr::ONE - main_current[0].into()) * main_current[1].into()) * (main_current[3].into() - AB::Expr::from_u64(16)) + (AB::Expr::ONE - main_current[0].into()) * (AB::Expr::ONE - main_current[1].into()) * (main_current[4].into() - AB::Expr::from_u64(5))); - builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].into()) * (main_current[5].into() - AB::Expr::from_u64(5)) + main_current[0].into() * (main_current[4].into() - AB::Expr::from_u64(4))); - builder.assert_zero::<_>(main_current[0].into() * (main_current[5].into() - AB::Expr::from_u64(20)) + (AB::Expr::ONE - main_current[0].into()) * main_current[1].into() * (main_current[4].into() - AB::Expr::from_u64(31))); + builder.when_first_row().assert_zero::<_>(main_current[5].clone().into()); + builder.assert_zero::<_>((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * (main_current[3].clone().into() - AB::Expr::from_u64(16)) + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(5))); + builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(5)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(4))); + builder.assert_zero::<_>(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(20)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(31))); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_combine_simple_plonky3.rs b/air-script/tests/selectors/selectors_combine_simple_plonky3.rs index c981e950b..5bee29c5a 100644 --- a/air-script/tests/selectors/selectors_combine_simple_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_simple_plonky3.rs @@ -37,8 +37,8 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[3].into()); - builder.when_transition().assert_zero::<_>(main_next[1].into() - main_current[2].into()); - builder.when_transition().assert_zero::<_>(main_current[3].into() * (main_next[0].into() - (main_current[0].into() + main_current[1].into())) + (AB::Expr::ONE - main_current[3].into()) * (main_next[0].into() - main_current[0].into() * main_current[1].into())); + builder.when_first_row().assert_zero::<_>(main_current[3].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[1].clone().into() - main_current[2].clone().into()); + builder.when_transition().assert_zero::<_>(main_current[3].clone().into() * (main_next[0].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())) + (AB::Expr::ONE - main_current[3].clone().into()) * (main_next[0].clone().into() - main_current[0].clone().into() * main_current[1].clone().into())); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs b/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs index 1a937a640..cd222b9b1 100644 --- a/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs @@ -37,9 +37,9 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[5].into()); - builder.assert_zero::<_>((main_current[0].into() + (AB::Expr::ONE - main_current[0].into()) * main_current[1].into()) * main_current[3].into() + (AB::Expr::ONE - main_current[0].into()) * (AB::Expr::ONE - main_current[1].into()) * (main_current[4].into() - AB::Expr::from_u64(8))); - builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].into()) * (main_current[5].into() - AB::Expr::from_u64(8)) + main_current[0].into() * (main_current[4].into() - AB::Expr::from_u64(2))); - builder.assert_zero::<_>(main_current[0].into() * (main_current[5].into() - AB::Expr::from_u64(4)) + (AB::Expr::ONE - main_current[0].into()) * main_current[1].into() * (main_current[4].into() - AB::Expr::from_u64(6))); + builder.when_first_row().assert_zero::<_>(main_current[5].clone().into()); + builder.assert_zero::<_>((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * main_current[3].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(8))); + builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(8)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(2))); + builder.assert_zero::<_>(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(4)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(6))); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_plonky3.rs b/air-script/tests/selectors/selectors_plonky3.rs index 7b0b2f210..1c9c27a7e 100644 --- a/air-script/tests/selectors/selectors_plonky3.rs +++ b/air-script/tests/selectors/selectors_plonky3.rs @@ -37,8 +37,8 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[3].into()); - builder.when_transition().assert_zero::<_>(main_current[0].into() * (AB::Expr::ONE - main_current[1].into()) * main_next[3].into()); - builder.when_transition().assert_zero::<_>(main_current[0].into() * main_current[1].into() * main_current[2].into() * (main_next[3].into() - main_current[3].into()) + (AB::Expr::ONE - main_current[1].into()) * (AB::Expr::ONE - main_current[2].into()) * (main_next[3].into() - AB::Expr::ONE)); + builder.when_first_row().assert_zero::<_>(main_current[3].clone().into()); + builder.when_transition().assert_zero::<_>(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); + builder.when_transition().assert_zero::<_>(main_current[0].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs b/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs index 10fd5fb98..2f59c7abb 100644 --- a/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs +++ b/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs @@ -37,8 +37,8 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[3].into()); - builder.when_transition().assert_zero::<_>(main_current[0].into() * (AB::Expr::ONE - main_current[1].into()) * main_next[3].into()); - builder.when_transition().assert_zero::<_>(main_current[1].into() * main_current[2].into() * main_current[0].into() * (main_next[3].into() - main_current[3].into()) + (AB::Expr::ONE - main_current[1].into()) * (AB::Expr::ONE - main_current[2].into()) * (main_next[3].into() - AB::Expr::ONE)); + builder.when_first_row().assert_zero::<_>(main_current[3].clone().into()); + builder.when_transition().assert_zero::<_>(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); + builder.when_transition().assert_zero::<_>(main_current[1].clone().into() * main_current[2].clone().into() * main_current[0].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); } } \ No newline at end of file diff --git a/air-script/tests/system/system_plonky3.rs b/air-script/tests/system/system_plonky3.rs index ca2204da0..b4c330ab3 100644 --- a/air-script/tests/system/system_plonky3.rs +++ b/air-script/tests/system/system_plonky3.rs @@ -37,7 +37,7 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].into()); - builder.when_transition().assert_zero::<_>(main_next[0].into() - (main_current[0].into() + AB::Expr::ONE)); + builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); } } \ No newline at end of file diff --git a/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs b/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs index 08bf27975..f80168286 100644 --- a/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs +++ b/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs @@ -37,8 +37,8 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[8].into()); - builder.when_transition().assert_zero::<_>(main_next[2].into() - (main_current[2].into() + AB::Expr::ONE)); - builder.when_transition().assert_zero::<_>(main_next[1].into() - (main_current[1].into() - AB::Expr::ONE)); + builder.when_first_row().assert_zero::<_>(main_current[8].clone().into()); + builder.when_transition().assert_zero::<_>(main_next[2].clone().into() - (main_current[2].clone().into() + AB::Expr::ONE)); + builder.when_transition().assert_zero::<_>(main_next[1].clone().into() - (main_current[1].clone().into() - AB::Expr::ONE)); } } \ No newline at end of file diff --git a/air-script/tests/variables/variables_plonky3.rs b/air-script/tests/variables/variables_plonky3.rs index 48ce365c8..acd8472df 100644 --- a/air-script/tests/variables/variables_plonky3.rs +++ b/air-script/tests/variables/variables_plonky3.rs @@ -38,11 +38,11 @@ impl Air for main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[1].into()); - builder.when_last_row().assert_zero::<_>(main_current[1].into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[0].into() * main_current[0].into() - main_current[0].into()); - builder.when_transition().assert_zero::<_>(periodic_values[0].into() * (main_next[0].into() - main_current[0].into())); - builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].into()) * (main_current[3].into() - main_current[1].into() - main_current[2].into()) - (AB::Expr::from_u64(6) - (AB::Expr::from_u64(7) - main_current[0].into()))); - builder.when_transition().assert_zero::<_>(main_current[0].into() * (main_current[3].into() - main_current[1].into() * main_current[2].into()) - (AB::Expr::ONE - main_next[0].into())); + builder.when_first_row().assert_zero::<_>(main_current[1].clone().into()); + builder.when_last_row().assert_zero::<_>(main_current[1].clone().into() - AB::Expr::ONE); + builder.assert_zero::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.when_transition().assert_zero::<_>(periodic_values[0].into() * (main_next[0].clone().into() - main_current[0].clone().into())); + builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[3].clone().into() - main_current[1].clone().into() - main_current[2].clone().into()) - (AB::Expr::from_u64(6) - (AB::Expr::from_u64(7) - main_current[0].clone().into()))); + builder.when_transition().assert_zero::<_>(main_current[0].clone().into() * (main_current[3].clone().into() - main_current[1].clone().into() * main_current[2].clone().into()) - (AB::Expr::ONE - main_next[0].clone().into())); } } \ No newline at end of file diff --git a/codegen/plonky3/src/air/graph.rs b/codegen/plonky3/src/air/graph.rs index fb9e816b6..339ec5ca0 100644 --- a/codegen/plonky3/src/air/graph.rs +++ b/codegen/plonky3/src/air/graph.rs @@ -14,10 +14,10 @@ impl Codegen for TraceAccess { let frame = self.segment.to_string(); let row_offset = match self.row_offset { 0 => { - format!("current[{}].into()", self.column) + format!("current[{}].clone().into()", self.column) }, 1 => { - format!("next[{}].into()", self.column) + format!("next[{}].clone().into()", self.column) }, _ => panic!("Plonky3 doesn't support row offsets greater than 1."), }; From 4138e94a1ec0a843b96642b38ed4c2b5a573be11 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Wed, 5 Nov 2025 12:13:28 +0100 Subject: [PATCH 03/22] feat: Update to target AirScriptAir and AirScriptBuilder traits --- air-script/tests/binary/binary_plonky3.rs | 34 +- air-script/tests/binary/test_air_plonky3.rs | 6 +- air-script/tests/bitwise/bitwise_plonky3.rs | 64 ++-- air-script/tests/bitwise/test_air_plonky3.rs | 6 +- .../tests/buses/buses_complex_plonky3.rs | 34 +- .../tests/buses/buses_simple_plonky3.rs | 28 +- .../buses_varlen_boundary_both_plonky3.rs | 28 +- .../buses_varlen_boundary_first_plonky3.rs | 28 +- .../buses_varlen_boundary_last_plonky3.rs | 28 +- air-script/tests/buses/test_air_plonky3.rs | 6 +- .../computed_indices_complex_plonky3.rs | 32 +- .../computed_indices_simple_plonky3.rs | 46 +-- .../constant_in_range_plonky3.rs | 32 +- .../constant_in_range/test_air_plonky3.rs | 6 +- .../tests/constants/constants_plonky3.rs | 50 +-- .../tests/constants/test_air_plonky3.rs | 6 +- .../constraint_comprehension_plonky3.rs | 38 ++- .../test_air_plonky3.rs | 6 +- .../tests/evaluators/evaluators_plonky3.rs | 50 +-- .../tests/evaluators/test_air_plonky3.rs | 6 +- .../tests/fibonacci/fibonacci_plonky3.rs | 38 ++- .../tests/fibonacci/test_air_plonky3.rs | 6 +- .../functions/functions_complex_plonky3.rs | 34 +- .../functions/functions_simple_plonky3.rs | 46 +-- .../tests/functions/test_air_plonky3.rs | 6 +- air-script/tests/helpers/mod.rs | 9 +- air-script/tests/helpers/plonky3_traits.rs | 299 ++++++++++++++++++ .../indexed_trace_access_plonky3.rs | 32 +- .../indexed_trace_access/test_air_plonky3.rs | 6 +- .../list_comprehension_nested_plonky3.rs | 36 ++- .../list_comprehension_plonky3.rs | 42 ++- .../list_comprehension/test_air_plonky3.rs | 6 +- .../list_folding/list_folding_plonky3.rs | 38 ++- .../tests/list_folding/test_air_plonky3.rs | 6 +- .../periodic_columns_plonky3.rs | 34 +- .../periodic_columns/test_air_plonky3.rs | 6 +- .../tests/pub_inputs/pub_inputs_plonky3.rs | 46 +-- .../tests/pub_inputs/test_air_plonky3.rs | 6 +- .../selectors_combine_complex_plonky3.rs | 36 ++- .../selectors_combine_simple_plonky3.rs | 34 +- ...ombine_with_list_comprehensions_plonky3.rs | 36 ++- .../tests/selectors/selectors_plonky3.rs | 34 +- .../selectors_with_evaluators_plonky3.rs | 34 +- .../tests/selectors/test_air_plonky3.rs | 6 +- air-script/tests/system/system_plonky3.rs | 32 +- air-script/tests/system/test_air_plonky3.rs | 6 +- .../trace_col_groups/test_air_plonky3.rs | 6 +- .../trace_col_groups_plonky3.rs | 34 +- .../tests/variables/test_air_plonky3.rs | 6 +- .../tests/variables/variables_plonky3.rs | 40 ++- .../plonky3/src/air/boundary_constraints.rs | 4 +- .../plonky3/src/air/integrity_constraints.rs | 4 +- codegen/plonky3/src/air/mod.rs | 66 ++-- codegen/plonky3/src/imports.rs | 8 +- 54 files changed, 1119 insertions(+), 497 deletions(-) create mode 100644 air-script/tests/helpers/plonky3_traits.rs diff --git a/air-script/tests/binary/binary_plonky3.rs b/air-script/tests/binary/binary_plonky3.rs index 95f14d739..1660f5e69 100644 --- a/air-script/tests/binary/binary_plonky3.rs +++ b/air-script/tests/binary/binary_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 2; @@ -21,24 +21,34 @@ impl BaseAirWithPublicValues for BinaryAir { } } -impl BaseAirWithPeriodicColumns for BinaryAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for BinaryAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for BinaryAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into() - public_values[0].into()); - builder.assert_zero::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); - builder.assert_zero::<_>(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into() - public_values[0].into()); + builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.assert_zero_ext::<_>(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); + } +} + +impl Air for BinaryAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/binary/test_air_plonky3.rs b/air-script/tests/binary/test_air_plonky3.rs index cb06fb5f4..266a003e1 100644 --- a/air-script/tests/binary/test_air_plonky3.rs +++ b/air-script/tests/binary/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ binary::binary_plonky3::{BinaryAir, NUM_COLUMNS}, - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { @@ -52,4 +52,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, BinaryAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, BinaryAir); diff --git a/air-script/tests/bitwise/bitwise_plonky3.rs b/air-script/tests/bitwise/bitwise_plonky3.rs index 2c58d50e2..093b396e6 100644 --- a/air-script/tests/bitwise/bitwise_plonky3.rs +++ b/air-script/tests/bitwise/bitwise_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 14; @@ -21,41 +21,51 @@ impl BaseAirWithPublicValues for BitwiseAir { } } -impl BaseAirWithPeriodicColumns for BitwiseAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for BitwiseAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ vec![F::from_u64(1), F::from_u64(0), F::from_u64(0), F::from_u64(0), F::from_u64(0), F::from_u64(0), F::from_u64(0), F::from_u64(0)], vec![F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(0)], ] } -} -impl Air for BitwiseAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[13].clone().into()); - builder.assert_zero::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); - builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[0].clone().into() - main_current[0].clone().into())); - builder.assert_zero::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); - builder.assert_zero::<_>(main_current[4].clone().into() * main_current[4].clone().into() - main_current[4].clone().into()); - builder.assert_zero::<_>(main_current[5].clone().into() * main_current[5].clone().into() - main_current[5].clone().into()); - builder.assert_zero::<_>(main_current[6].clone().into() * main_current[6].clone().into() - main_current[6].clone().into()); - builder.assert_zero::<_>(main_current[7].clone().into() * main_current[7].clone().into() - main_current[7].clone().into()); - builder.assert_zero::<_>(main_current[8].clone().into() * main_current[8].clone().into() - main_current[8].clone().into()); - builder.assert_zero::<_>(main_current[9].clone().into() * main_current[9].clone().into() - main_current[9].clone().into()); - builder.assert_zero::<_>(main_current[10].clone().into() * main_current[10].clone().into() - main_current[10].clone().into()); - builder.assert_zero::<_>(periodic_values[0].into() * (main_current[1].clone().into() - (main_current[3].clone().into() + main_current[4].clone().into().double() + AB::Expr::from_u64(4) * main_current[5].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into()))); - builder.assert_zero::<_>(periodic_values[0].into() * (main_current[2].clone().into() - (main_current[7].clone().into() + main_current[8].clone().into().double() + AB::Expr::from_u64(4) * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[10].clone().into()))); - builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[1].clone().into() - (main_current[1].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[4].clone().into().double() + AB::Expr::from_u64(4) * main_current[5].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into()))); - builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[2].clone().into() - (main_current[2].clone().into() * AB::Expr::from_u64(16) + main_current[7].clone().into() + main_current[8].clone().into().double() + AB::Expr::from_u64(4) * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[10].clone().into()))); - builder.assert_zero::<_>(periodic_values[0].into() * main_current[11].clone().into()); - builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_current[12].clone().into() - main_next[11].clone().into())); - builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() * main_current[7].clone().into() + main_current[4].clone().into().double() * main_current[8].clone().into() + AB::Expr::from_u64(4) * main_current[5].clone().into() * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into() * main_current[10].clone().into())) + main_current[0].clone().into() * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[7].clone().into() - main_current[3].clone().into().double() * main_current[7].clone().into() + (main_current[4].clone().into() + main_current[8].clone().into() - main_current[4].clone().into().double() * main_current[8].clone().into()).double() + AB::Expr::from_u64(4) * (main_current[5].clone().into() + main_current[9].clone().into() - main_current[5].clone().into().double() * main_current[9].clone().into()) + AB::Expr::from_u64(8) * (main_current[6].clone().into() + main_current[10].clone().into() - main_current[6].clone().into().double() * main_current[10].clone().into())))); + builder.when_first_row().assert_zero_ext::<_>(main_current[13].clone().into()); + builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.when_transition().assert_zero_ext::<_>(periodic_values[1].into() * (main_next[0].clone().into() - main_current[0].clone().into())); + builder.assert_zero_ext::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); + builder.assert_zero_ext::<_>(main_current[4].clone().into() * main_current[4].clone().into() - main_current[4].clone().into()); + builder.assert_zero_ext::<_>(main_current[5].clone().into() * main_current[5].clone().into() - main_current[5].clone().into()); + builder.assert_zero_ext::<_>(main_current[6].clone().into() * main_current[6].clone().into() - main_current[6].clone().into()); + builder.assert_zero_ext::<_>(main_current[7].clone().into() * main_current[7].clone().into() - main_current[7].clone().into()); + builder.assert_zero_ext::<_>(main_current[8].clone().into() * main_current[8].clone().into() - main_current[8].clone().into()); + builder.assert_zero_ext::<_>(main_current[9].clone().into() * main_current[9].clone().into() - main_current[9].clone().into()); + builder.assert_zero_ext::<_>(main_current[10].clone().into() * main_current[10].clone().into() - main_current[10].clone().into()); + builder.assert_zero_ext::<_>(periodic_values[0].into() * (main_current[1].clone().into() - (main_current[3].clone().into() + main_current[4].clone().into().double() + AB::Expr::from_u64(4) * main_current[5].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into()))); + builder.assert_zero_ext::<_>(periodic_values[0].into() * (main_current[2].clone().into() - (main_current[7].clone().into() + main_current[8].clone().into().double() + AB::Expr::from_u64(4) * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[10].clone().into()))); + builder.when_transition().assert_zero_ext::<_>(periodic_values[1].into() * (main_next[1].clone().into() - (main_current[1].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[4].clone().into().double() + AB::Expr::from_u64(4) * main_current[5].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into()))); + builder.when_transition().assert_zero_ext::<_>(periodic_values[1].into() * (main_next[2].clone().into() - (main_current[2].clone().into() * AB::Expr::from_u64(16) + main_current[7].clone().into() + main_current[8].clone().into().double() + AB::Expr::from_u64(4) * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[10].clone().into()))); + builder.assert_zero_ext::<_>(periodic_values[0].into() * main_current[11].clone().into()); + builder.when_transition().assert_zero_ext::<_>(periodic_values[1].into() * (main_current[12].clone().into() - main_next[11].clone().into())); + builder.assert_zero_ext::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() * main_current[7].clone().into() + main_current[4].clone().into().double() * main_current[8].clone().into() + AB::Expr::from_u64(4) * main_current[5].clone().into() * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into() * main_current[10].clone().into())) + main_current[0].clone().into() * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[7].clone().into() - main_current[3].clone().into().double() * main_current[7].clone().into() + (main_current[4].clone().into() + main_current[8].clone().into() - main_current[4].clone().into().double() * main_current[8].clone().into()).double() + AB::Expr::from_u64(4) * (main_current[5].clone().into() + main_current[9].clone().into() - main_current[5].clone().into().double() * main_current[9].clone().into()) + AB::Expr::from_u64(8) * (main_current[6].clone().into() + main_current[10].clone().into() - main_current[6].clone().into().double() * main_current[10].clone().into())))); + } +} + +impl Air for BitwiseAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/bitwise/test_air_plonky3.rs b/air-script/tests/bitwise/test_air_plonky3.rs index d3c6efcaa..94b5aa172 100644 --- a/air-script/tests/bitwise/test_air_plonky3.rs +++ b/air-script/tests/bitwise/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ bitwise::bitwise_plonky3::{BitwiseAir, NUM_COLUMNS}, - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { @@ -90,4 +90,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, BitwiseAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, BitwiseAir); diff --git a/air-script/tests/buses/buses_complex_plonky3.rs b/air-script/tests/buses/buses_complex_plonky3.rs index ef56d20b3..710e04cd2 100644 --- a/air-script/tests/buses/buses_complex_plonky3.rs +++ b/air-script/tests/buses/buses_complex_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 5; @@ -21,24 +21,34 @@ impl BaseAirWithPublicValues for BusesAir { } } -impl BaseAirWithPeriodicColumns for BusesAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for BusesAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 4; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for BusesAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); - builder.assert_zero::<_>(main_current[2].clone().into() * main_current[2].clone().into() - main_current[2].clone().into()); - builder.assert_zero::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); + builder.assert_zero_ext::<_>(main_current[2].clone().into() * main_current[2].clone().into() - main_current[2].clone().into()); + builder.assert_zero_ext::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); + } +} + +impl Air for BusesAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/buses/buses_simple_plonky3.rs b/air-script/tests/buses/buses_simple_plonky3.rs index 6ea46ea4b..5b641ad49 100644 --- a/air-script/tests/buses/buses_simple_plonky3.rs +++ b/air-script/tests/buses/buses_simple_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 1; @@ -21,21 +21,31 @@ impl BaseAirWithPublicValues for BusesAir { } } -impl BaseAirWithPeriodicColumns for BusesAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for BusesAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 3; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for BusesAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); } +} + +impl Air for BusesAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); + } } \ No newline at end of file diff --git a/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs b/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs index e8f0c1253..60627dc6c 100644 --- a/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs +++ b/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 1; @@ -21,21 +21,31 @@ impl BaseAirWithPublicValues for BusesAir { } } -impl BaseAirWithPeriodicColumns for BusesAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for BusesAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 3; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for BusesAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); } +} + +impl Air for BusesAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); + } } \ No newline at end of file diff --git a/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs b/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs index 6ea46ea4b..5b641ad49 100644 --- a/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs +++ b/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 1; @@ -21,21 +21,31 @@ impl BaseAirWithPublicValues for BusesAir { } } -impl BaseAirWithPeriodicColumns for BusesAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for BusesAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 3; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for BusesAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); } +} + +impl Air for BusesAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); + } } \ No newline at end of file diff --git a/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs b/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs index 6ea46ea4b..5b641ad49 100644 --- a/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs +++ b/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 1; @@ -21,21 +21,31 @@ impl BaseAirWithPublicValues for BusesAir { } } -impl BaseAirWithPeriodicColumns for BusesAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for BusesAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 3; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for BusesAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); } +} + +impl Air for BusesAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); + } } \ No newline at end of file diff --git a/air-script/tests/buses/test_air_plonky3.rs b/air-script/tests/buses/test_air_plonky3.rs index 1b323208b..98502069a 100644 --- a/air-script/tests/buses/test_air_plonky3.rs +++ b/air-script/tests/buses/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ buses::buses_complex_plonky3::{BusesAir, NUM_COLUMNS}, - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { @@ -52,4 +52,4 @@ fn generate_inputs() -> Vec { vec![1; 2] } -generate_air_plonky3_test!(test_air_plonky3, BusesAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, BusesAir); diff --git a/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs b/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs index 099828dc5..99b23171c 100644 --- a/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs +++ b/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 4; @@ -21,23 +21,33 @@ impl BaseAirWithPublicValues for ComputedIndicesAir { } } -impl BaseAirWithPeriodicColumns for ComputedIndicesAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for ComputedIndicesAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for ComputedIndicesAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); - builder.assert_zero::<_>(main_current[2].clone().into() * AB::Expr::from_u64(3) + main_current[3].clone().into() * AB::Expr::from_u64(4)); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); + builder.assert_zero_ext::<_>(main_current[2].clone().into() * AB::Expr::from_u64(3) + main_current[3].clone().into() * AB::Expr::from_u64(4)); + } +} + +impl Air for ComputedIndicesAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs b/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs index 8e821b4a8..00fac14c1 100644 --- a/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs +++ b/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 8; @@ -21,30 +21,40 @@ impl BaseAirWithPublicValues for ComputedIndicesAir { } } -impl BaseAirWithPeriodicColumns for ComputedIndicesAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for ComputedIndicesAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for ComputedIndicesAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); - builder.assert_zero::<_>(main_current[0].clone().into()); - builder.assert_zero::<_>(main_current[1].clone().into() - AB::Expr::from_u64(2)); - builder.assert_zero::<_>(main_current[2].clone().into() - AB::Expr::from_u64(4)); - builder.assert_zero::<_>(main_current[3].clone().into() - AB::Expr::from_u64(6)); - builder.when_transition().assert_zero::<_>(main_next[4].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[5].clone().into() - main_current[5].clone().into().double()); - builder.when_transition().assert_zero::<_>(main_next[6].clone().into() - AB::Expr::from_u64(6) * main_current[6].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[7].clone().into() - AB::Expr::from_u64(12) * main_current[7].clone().into()); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); + builder.assert_zero_ext::<_>(main_current[0].clone().into()); + builder.assert_zero_ext::<_>(main_current[1].clone().into() - AB::Expr::from_u64(2)); + builder.assert_zero_ext::<_>(main_current[2].clone().into() - AB::Expr::from_u64(4)); + builder.assert_zero_ext::<_>(main_current[3].clone().into() - AB::Expr::from_u64(6)); + builder.when_transition().assert_zero_ext::<_>(main_next[4].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[5].clone().into() - main_current[5].clone().into().double()); + builder.when_transition().assert_zero_ext::<_>(main_next[6].clone().into() - AB::Expr::from_u64(6) * main_current[6].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[7].clone().into() - AB::Expr::from_u64(12) * main_current[7].clone().into()); + } +} + +impl Air for ComputedIndicesAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/constant_in_range/constant_in_range_plonky3.rs b/air-script/tests/constant_in_range/constant_in_range_plonky3.rs index 88013d4f3..5163db980 100644 --- a/air-script/tests/constant_in_range/constant_in_range_plonky3.rs +++ b/air-script/tests/constant_in_range/constant_in_range_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 12; @@ -21,23 +21,33 @@ impl BaseAirWithPublicValues for ConstantInRangeAir { } } -impl BaseAirWithPeriodicColumns for ConstantInRangeAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for ConstantInRangeAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for ConstantInRangeAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[6].clone().into()); - builder.assert_zero::<_>(main_current[0].clone().into() - (main_current[1].clone().into() - main_current[4].clone().into() - main_current[8].clone().into() + AB::Expr::ONE + main_current[2].clone().into() - main_current[5].clone().into() - main_current[9].clone().into() + AB::Expr::from_u64(2) + main_current[3].clone().into() - main_current[6].clone().into() - main_current[10].clone().into())); + builder.when_first_row().assert_zero_ext::<_>(main_current[6].clone().into()); + builder.assert_zero_ext::<_>(main_current[0].clone().into() - (main_current[1].clone().into() - main_current[4].clone().into() - main_current[8].clone().into() + AB::Expr::ONE + main_current[2].clone().into() - main_current[5].clone().into() - main_current[9].clone().into() + AB::Expr::from_u64(2) + main_current[3].clone().into() - main_current[6].clone().into() - main_current[10].clone().into())); + } +} + +impl Air for ConstantInRangeAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/constant_in_range/test_air_plonky3.rs b/air-script/tests/constant_in_range/test_air_plonky3.rs index 56e1dcb11..d999eafd2 100644 --- a/air-script/tests/constant_in_range/test_air_plonky3.rs +++ b/air-script/tests/constant_in_range/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ constant_in_range::constant_in_range_plonky3::{ConstantInRangeAir, NUM_COLUMNS}, - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { @@ -71,4 +71,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, ConstantInRangeAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, ConstantInRangeAir); diff --git a/air-script/tests/constants/constants_plonky3.rs b/air-script/tests/constants/constants_plonky3.rs index ee2300915..088ab7f88 100644 --- a/air-script/tests/constants/constants_plonky3.rs +++ b/air-script/tests/constants/constants_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 7; @@ -21,32 +21,42 @@ impl BaseAirWithPublicValues for ConstantsAir { } } -impl BaseAirWithPeriodicColumns for ConstantsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for ConstantsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for ConstantsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into() - AB::Expr::ONE); - builder.when_first_row().assert_zero::<_>(main_current[1].clone().into() - AB::Expr::ONE); - builder.when_first_row().assert_zero::<_>(main_current[2].clone().into()); - builder.when_first_row().assert_zero::<_>(main_current[3].clone().into() - AB::Expr::ONE); - builder.when_first_row().assert_zero::<_>(main_current[4].clone().into() - AB::Expr::ONE); - builder.when_last_row().assert_zero::<_>(main_current[6].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); - builder.when_transition().assert_zero::<_>(main_next[1].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[2].clone().into() - main_current[2].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[5].clone().into() - (main_current[5].clone().into() + AB::Expr::ONE)); - builder.assert_zero::<_>(main_current[4].clone().into() - AB::Expr::ONE); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into() - AB::Expr::ONE); + builder.when_first_row().assert_zero_ext::<_>(main_current[1].clone().into() - AB::Expr::ONE); + builder.when_first_row().assert_zero_ext::<_>(main_current[2].clone().into()); + builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into() - AB::Expr::ONE); + builder.when_first_row().assert_zero_ext::<_>(main_current[4].clone().into() - AB::Expr::ONE); + builder.when_last_row().assert_zero_ext::<_>(main_current[6].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); + builder.when_transition().assert_zero_ext::<_>(main_next[1].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[2].clone().into() - main_current[2].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[5].clone().into() - (main_current[5].clone().into() + AB::Expr::ONE)); + builder.assert_zero_ext::<_>(main_current[4].clone().into() - AB::Expr::ONE); + } +} + +impl Air for ConstantsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/constants/test_air_plonky3.rs b/air-script/tests/constants/test_air_plonky3.rs index 6eecb26fa..4f6032d7d 100644 --- a/air-script/tests/constants/test_air_plonky3.rs +++ b/air-script/tests/constants/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ constants::constants_plonky3::{ConstantsAir, NUM_COLUMNS}, - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { @@ -67,4 +67,4 @@ fn generate_inputs() -> Vec { vec![1; 32] } -generate_air_plonky3_test!(test_air_plonky3, ConstantsAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, ConstantsAir); diff --git a/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs b/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs index a79f98584..22fd4c228 100644 --- a/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs +++ b/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 14; @@ -21,26 +21,36 @@ impl BaseAirWithPublicValues for ConstraintComprehensionAir { } } -impl BaseAirWithPeriodicColumns for ConstraintComprehensionAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for ConstraintComprehensionAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for ConstraintComprehensionAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[8].clone().into()); - builder.assert_zero::<_>(main_current[6].clone().into() - main_current[10].clone().into()); - builder.assert_zero::<_>(main_current[7].clone().into() - main_current[11].clone().into()); - builder.assert_zero::<_>(main_current[8].clone().into() - main_current[12].clone().into()); - builder.assert_zero::<_>(main_current[9].clone().into() - main_current[13].clone().into()); + builder.when_first_row().assert_zero_ext::<_>(main_current[8].clone().into()); + builder.assert_zero_ext::<_>(main_current[6].clone().into() - main_current[10].clone().into()); + builder.assert_zero_ext::<_>(main_current[7].clone().into() - main_current[11].clone().into()); + builder.assert_zero_ext::<_>(main_current[8].clone().into() - main_current[12].clone().into()); + builder.assert_zero_ext::<_>(main_current[9].clone().into() - main_current[13].clone().into()); + } +} + +impl Air for ConstraintComprehensionAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/constraint_comprehension/test_air_plonky3.rs b/air-script/tests/constraint_comprehension/test_air_plonky3.rs index ceab24925..1753ec70f 100644 --- a/air-script/tests/constraint_comprehension/test_air_plonky3.rs +++ b/air-script/tests/constraint_comprehension/test_air_plonky3.rs @@ -16,8 +16,8 @@ use crate::{ constraint_comprehension::constraint_comprehension_plonky3::{ ConstraintComprehensionAir, NUM_COLUMNS, }, - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { @@ -54,4 +54,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, ConstraintComprehensionAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, ConstraintComprehensionAir); diff --git a/air-script/tests/evaluators/evaluators_plonky3.rs b/air-script/tests/evaluators/evaluators_plonky3.rs index 0a3e2329f..e2d0cdb1c 100644 --- a/air-script/tests/evaluators/evaluators_plonky3.rs +++ b/air-script/tests/evaluators/evaluators_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 7; @@ -21,32 +21,42 @@ impl BaseAirWithPublicValues for EvaluatorsAir { } } -impl BaseAirWithPeriodicColumns for EvaluatorsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for EvaluatorsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for EvaluatorsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - main_current[0].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[2].clone().into() - main_current[2].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[6].clone().into() - main_current[6].clone().into()); - builder.assert_zero::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); - builder.assert_zero::<_>(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); - builder.assert_zero::<_>(main_current[2].clone().into() * main_current[2].clone().into() - main_current[2].clone().into()); - builder.assert_zero::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); - builder.assert_zero::<_>(main_current[4].clone().into()); - builder.assert_zero::<_>(main_current[5].clone().into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[6].clone().into() - AB::Expr::from_u64(4)); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - main_current[0].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[2].clone().into() - main_current[2].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[6].clone().into() - main_current[6].clone().into()); + builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.assert_zero_ext::<_>(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); + builder.assert_zero_ext::<_>(main_current[2].clone().into() * main_current[2].clone().into() - main_current[2].clone().into()); + builder.assert_zero_ext::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); + builder.assert_zero_ext::<_>(main_current[4].clone().into()); + builder.assert_zero_ext::<_>(main_current[5].clone().into() - AB::Expr::ONE); + builder.assert_zero_ext::<_>(main_current[6].clone().into() - AB::Expr::from_u64(4)); + } +} + +impl Air for EvaluatorsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/evaluators/test_air_plonky3.rs b/air-script/tests/evaluators/test_air_plonky3.rs index 7fed6ebc2..fe22d06d8 100644 --- a/air-script/tests/evaluators/test_air_plonky3.rs +++ b/air-script/tests/evaluators/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ evaluators::evaluators_plonky3::{EvaluatorsAir, NUM_COLUMNS}, - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { @@ -67,4 +67,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, EvaluatorsAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, EvaluatorsAir); diff --git a/air-script/tests/fibonacci/fibonacci_plonky3.rs b/air-script/tests/fibonacci/fibonacci_plonky3.rs index ec88598e1..f2c5d8aad 100644 --- a/air-script/tests/fibonacci/fibonacci_plonky3.rs +++ b/air-script/tests/fibonacci/fibonacci_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 2; @@ -21,26 +21,36 @@ impl BaseAirWithPublicValues for FibonacciAir { } } -impl BaseAirWithPeriodicColumns for FibonacciAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for FibonacciAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for FibonacciAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into() - public_values[0].into()); - builder.when_first_row().assert_zero::<_>(main_current[1].clone().into() - public_values[1].into()); - builder.when_last_row().assert_zero::<_>(main_current[1].clone().into() - public_values[2].into()); - builder.when_transition().assert_zero::<_>(main_next[1].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())); - builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - main_current[1].clone().into()); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into() - public_values[0].into()); + builder.when_first_row().assert_zero_ext::<_>(main_current[1].clone().into() - public_values[1].into()); + builder.when_last_row().assert_zero_ext::<_>(main_current[1].clone().into() - public_values[2].into()); + builder.when_transition().assert_zero_ext::<_>(main_next[1].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())); + builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - main_current[1].clone().into()); + } +} + +impl Air for FibonacciAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/fibonacci/test_air_plonky3.rs b/air-script/tests/fibonacci/test_air_plonky3.rs index 6a01a91b6..28afeb872 100644 --- a/air-script/tests/fibonacci/test_air_plonky3.rs +++ b/air-script/tests/fibonacci/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ fibonacci::fibonacci_plonky3::{FibonacciAir, NUM_COLUMNS}, - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { @@ -54,4 +54,4 @@ fn generate_inputs() -> Vec { vec![one, one, last] } -generate_air_plonky3_test!(test_air_plonky3, FibonacciAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, FibonacciAir); diff --git a/air-script/tests/functions/functions_complex_plonky3.rs b/air-script/tests/functions/functions_complex_plonky3.rs index 6005f5123..83497ae05 100644 --- a/air-script/tests/functions/functions_complex_plonky3.rs +++ b/air-script/tests/functions/functions_complex_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 17; @@ -21,24 +21,34 @@ impl BaseAirWithPublicValues for FunctionsAir { } } -impl BaseAirWithPeriodicColumns for FunctionsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for FunctionsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for FunctionsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[3].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[16].clone().into() - main_current[16].clone().into() * ((main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() + main_current[3].clone().into() * main_current[3].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_current[2].clone().into() + main_current[3].clone().into() * main_current[1].clone().into() * (AB::Expr::ONE - main_current[2].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into())) * main_current[0].clone().into() - main_current[0].clone().into() + AB::Expr::ONE)); - builder.when_transition().assert_zero::<_>(main_next[3].clone().into() - (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() + main_current[8].clone().into() + main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() + main_current[14].clone().into() + main_current[15].clone().into() + AB::Expr::ONE).double()); + builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[16].clone().into() - main_current[16].clone().into() * ((main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() + main_current[3].clone().into() * main_current[3].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_current[2].clone().into() + main_current[3].clone().into() * main_current[1].clone().into() * (AB::Expr::ONE - main_current[2].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into())) * main_current[0].clone().into() - main_current[0].clone().into() + AB::Expr::ONE)); + builder.when_transition().assert_zero_ext::<_>(main_next[3].clone().into() - (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() + main_current[8].clone().into() + main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() + main_current[14].clone().into() + main_current[15].clone().into() + AB::Expr::ONE).double()); + } +} + +impl Air for FunctionsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/functions/functions_simple_plonky3.rs b/air-script/tests/functions/functions_simple_plonky3.rs index 4ea30b778..3bce53acb 100644 --- a/air-script/tests/functions/functions_simple_plonky3.rs +++ b/air-script/tests/functions/functions_simple_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 9; @@ -21,30 +21,40 @@ impl BaseAirWithPublicValues for FunctionsAir { } } -impl BaseAirWithPeriodicColumns for FunctionsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for FunctionsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for FunctionsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[3].clone().into()); - builder.assert_zero::<_>(main_current[0].clone().into() * main_current[3].clone().into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() * main_current[3].clone().into() - AB::Expr::ONE); - builder.assert_zero::<_>((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[0].clone().into() * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[1].clone().into() + (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() - AB::Expr::ONE); - builder.assert_zero::<_>((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * AB::Expr::from_u64(4) - AB::Expr::ONE); + builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into()); + builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[3].clone().into() - AB::Expr::ONE); + builder.assert_zero_ext::<_>(main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() * main_current[3].clone().into() - AB::Expr::ONE); + builder.assert_zero_ext::<_>((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero_ext::<_>(main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero_ext::<_>(main_current[1].clone().into() + (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero_ext::<_>(main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero_ext::<_>((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * AB::Expr::from_u64(4) - AB::Expr::ONE); + } +} + +impl Air for FunctionsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/functions/test_air_plonky3.rs b/air-script/tests/functions/test_air_plonky3.rs index 5ef13dbf9..7692bc485 100644 --- a/air-script/tests/functions/test_air_plonky3.rs +++ b/air-script/tests/functions/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ functions::functions_complex_plonky3::{FunctionsAir, NUM_COLUMNS}, - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { @@ -97,4 +97,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, FunctionsAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, FunctionsAir); diff --git a/air-script/tests/helpers/mod.rs b/air-script/tests/helpers/mod.rs index 846ff0fd2..077bab5f1 100644 --- a/air-script/tests/helpers/mod.rs +++ b/air-script/tests/helpers/mod.rs @@ -1,6 +1,11 @@ -mod plonky3_periodic_columns; +// Deprectated: use updated AirScriptAir and AirScriptBuilder traits instead +//mod plonky3_periodic_columns; +//pub use plonky3_periodic_columns::*; + +mod plonky3_traits; mod winterfell_test_helpers; -pub use plonky3_periodic_columns::*; pub use winterfell_test_helpers::*; pub mod macros; + +pub use plonky3_traits::*; diff --git a/air-script/tests/helpers/plonky3_traits.rs b/air-script/tests/helpers/plonky3_traits.rs new file mode 100644 index 000000000..64537f7e4 --- /dev/null +++ b/air-script/tests/helpers/plonky3_traits.rs @@ -0,0 +1,299 @@ +use p3_air::{ + Air, AirBuilder, AirBuilderWithPublicValues, ExtensionBuilder, PermutationAirBuilder, +}; +use p3_field::{ExtensionField, Field}; +use p3_matrix::{ + Matrix, + dense::{RowMajorMatrix, RowMajorMatrixView}, + stack::VerticalPair, +}; + +/// Miden/AirScript-specific AIR. Replaces BaseAir for this forked target. +pub trait AirScriptAir { + /// Compile-time shape for this AIR. + const MAIN_WIDTH: usize; + const AUX_WIDTH: usize; // EF aux columns used by buses/perm args + const PERIOD: usize; // 0 == no periodic columns + const NUM_ALPHA_CHALLENGES: usize; // alpha_powers().len() + + /// Periodic constants (base-field) backing periodic_evals(). + //fn periodic_table(&self) -> &'static [&'static [F]]; + fn periodic_table(&self) -> Vec>; + + /// Single entrypoint: encodes main + aux + boundary constraints. + fn eval(&self, builder: &mut AB) + where + AB: AirScriptBuilder; +} + +/// Target trait for AirScript codegen. Implemented by the prover. +pub trait AirScriptBuilder: + AirBuilder + AirBuilderWithPublicValues + ExtensionBuilder + PermutationAirBuilder +where + ::F: Field, +{ + /// EF evaluations of periodic columns at the AIR’s random point (z). Order defined by + /// AirScript. + fn periodic_evals(&self) -> &[::VarEF]; + + /// Global challenges in EF. (We can provide defaults; details not important here.) + fn alpha(&self) -> ::VarEF; + fn alpha_powers(&self) -> &[::VarEF]; + fn beta(&self) -> ::VarEF; + + /// Aux bus boundary values: EF finals, one per aux/bus column, carried in the proof. + fn aux_bus_boundary_values(&self) -> &[::VarEF]; +} + +// Helper macros for Plonky3 test generation + +/// Generates a Plonky3 AIR test function with the standard boilerplate +/// +/// # Arguments +/// * `test_name` - The identifier for the test function (e.g., `test_binary_air`) +/// * `air_name` - The identifier for the AIR struct (e.g., `BinaryAir`) +#[macro_export] +macro_rules! generate_air_plonky3_test_with_airscript_traits { + ($test_name:ident, $air_name:ident) => { + #[test] + fn $test_name() { + type Val = Goldilocks; + type Challenge = BinomialExtensionField; + + type ByteHash = Sha256; + type FieldHash = SerializingHasher; + type MyCompress = CompressionFunctionFromHasher; + type ValMmcs = MerkleTreeMmcs; + type ChallengeMmcs = ExtensionMmcs; + type Challenger = SerializingChallenger64>; + type Pcs = CirclePcs; + type MyConfig = StarkConfig; + + let byte_hash = ByteHash {}; + let field_hash = FieldHash::new(Sha256); + let compress = MyCompress::new(byte_hash); + let val_mmcs = ValMmcs::new(field_hash, compress); + let challenge_mmcs = ChallengeMmcs::new(val_mmcs.clone()); + let challenger = Challenger::from_hasher(vec![], byte_hash); + let fri_params = create_benchmark_fri_params(challenge_mmcs); + let pcs = Pcs { + mmcs: val_mmcs, + fri_params, + _phantom: PhantomData, + }; + let config = MyConfig::new(pcs, challenger); + + let inputs = generate_inputs(); + let inputs_goldilocks: Vec = + inputs.iter().map(|&x| Val::from_u32(x)).collect(); + + let trace = generate_trace_rows::(inputs); + + check_constraints_with_airscript_traits::(&$air_name {}, &trace, &inputs_goldilocks); + + /*let prove_with_periodic_columns = prove_with_periodic_columns(&config, &BitwiseAir {}, trace, &inputs_goldilocks); + verify_with_periodic_columns(&config, &BitwiseAir {}, &prove_with_periodic_columns, &inputs_goldilocks).expect("Verification failed");*/ + + /*let proof = prove(&config, &BitwiseAir {}, trace, &inputs_goldilocks); + verify(&config, &BitwiseAir {}, &proof, &inputs_goldilocks).expect("Verification failed");*/ + } + }; +} + +/// A builder that runs constraint assertions during testing. +/// +/// Used in conjunction with [`check_constraints`] to simulate +/// an execution trace and verify that the AIR logic enforces all constraints. +#[derive(Debug)] +pub struct DebugConstraintBuilderWithAirScriptTraits<'a, F: Field, EF: ExtensionField> { + /// The index of the row currently being evaluated. + row_index: usize, + /// A view of the current and next row as a vertical pair. + main: VerticalPair, RowMajorMatrixView<'a, F>>, + /// The public values provided for constraint validation (e.g. inputs or outputs). + public_values: &'a [F], + /// A flag indicating whether this is the first row. + is_first_row: F, + /// A flag indicating whether this is the last row. + is_last_row: F, + /// A flag indicating whether this is a transition row (not the last row). + is_transition: F, + /// The periodic columns provided for constraint validation. + periodic_columns: Vec, + alpha: EF, + alpha_powers: Vec, + beta: EF, + aux_bus_boundary_values: Vec, +} + +impl<'a, F, EF> AirBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> +where + F: Field, + EF: ExtensionField, +{ + type F = F; + type Expr = F; + type Var = F; + type M = VerticalPair, RowMajorMatrixView<'a, F>>; + + fn main(&self) -> Self::M { + self.main + } + + fn is_first_row(&self) -> Self::Expr { + self.is_first_row + } + + fn is_last_row(&self) -> Self::Expr { + self.is_last_row + } + + /// # Panics + /// This function panics if `size` is not `2`. + fn is_transition_window(&self, size: usize) -> Self::Expr { + if size == 2 { + self.is_transition + } else { + panic!("only supports a window size of 2") + } + } + + fn assert_zero>(&mut self, x: I) { + assert_eq!(x.into(), F::ZERO, "constraints had nonzero value on row {}", self.row_index); + } + + fn assert_eq, I2: Into>(&mut self, x: I1, y: I2) { + let x = x.into(); + let y = y.into(); + assert_eq!(x, y, "values didn't match on row {}: {} != {}", self.row_index, x, y); + } +} + +impl<'a, F, EF> AirBuilderWithPublicValues for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> +where + F: Field, + EF: ExtensionField, +{ + type PublicVar = Self::F; + + fn public_values(&self) -> &[Self::F] { + self.public_values + } +} + +impl<'a, F, EF> ExtensionBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> +where + F: Field, + EF: ExtensionField, +{ + type EF = EF; + + type ExprEF = EF; + + type VarEF = EF; + + fn assert_zero_ext(&mut self, x: I) + where + I: Into, + { + assert_eq!( + x.into(), + EF::ZERO, + "constraints on ext field had nonzero value on row {}", + self.row_index + ); + } +} + +impl<'a, F, EF> PermutationAirBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> +where + F: Field, + EF: ExtensionField, +{ + type MP = VerticalPair, RowMajorMatrixView<'a, EF>>; + + type RandomVar = EF; + + fn permutation(&self) -> Self::MP { + todo!() + } + + fn permutation_randomness(&self) -> &[Self::RandomVar] { + todo!() + } +} + +impl<'a, F, EF> AirScriptBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> +where + F: Field + Into, + EF: ExtensionField, +{ + fn periodic_evals(&self) -> &[::VarEF] { + self.periodic_columns.as_slice() + } + + fn alpha(&self) -> ::VarEF { + self.alpha + } + + fn alpha_powers(&self) -> &[::VarEF] { + self.alpha_powers.as_slice() + } + + fn beta(&self) -> ::VarEF { + self.beta + } + + fn aux_bus_boundary_values(&self) -> &[::VarEF] { + self.aux_bus_boundary_values.as_slice() + } +} + +pub(crate) fn check_constraints_with_airscript_traits( + air: &A, + main: &RowMajorMatrix, + public_values: &Vec, +) where + F: Field, + EF: ExtensionField, + A: for<'a> Air>, + A: AirScriptAir, +{ + let height = main.height(); + + (0..height).for_each(|i| { + let i_next = (i + 1) % height; + + let local = main.row_slice(i).unwrap(); // i < height so unwrap should never fail. + let next = main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail. + let main = VerticalPair::new( + RowMajorMatrixView::new_row(&*local), + RowMajorMatrixView::new_row(&*next), + ); + let periodic_columns_base: Vec<_> = + air.periodic_table().iter().map(|col| col[i % col.len()]).collect(); + let periodic_columns: Vec = + periodic_columns_base.iter().map(|&v| EF::from(v)).collect(); + let aux_bus_boundary_values: Vec<_> = (0..A::AUX_WIDTH).map(|_| EF::GENERATOR).collect(); + let alpha = EF::GENERATOR; // TODO + let beta = EF::GENERATOR; // TODO + + let mut builder = DebugConstraintBuilderWithAirScriptTraits { + row_index: i, + main, + public_values, + is_first_row: F::from_bool(i == 0), + is_last_row: F::from_bool(i == height - 1), + is_transition: F::from_bool(i != height - 1), + periodic_columns, + alpha, + beta, + alpha_powers: (0..A::NUM_ALPHA_CHALLENGES) + .map(|power| alpha.exp_u64(power as u64)) + .collect(), + aux_bus_boundary_values, + }; + + AirScriptAir::eval(air, &mut builder); + }); +} diff --git a/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs b/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs index c1026ca47..6a31ef663 100644 --- a/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs +++ b/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 4; @@ -21,23 +21,33 @@ impl BaseAirWithPublicValues for TraceAccessAir { } } -impl BaseAirWithPeriodicColumns for TraceAccessAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for TraceAccessAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for TraceAccessAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - (main_current[1].clone().into() + AB::Expr::ONE)); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - (main_current[1].clone().into() + AB::Expr::ONE)); + } +} + +impl Air for TraceAccessAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/indexed_trace_access/test_air_plonky3.rs b/air-script/tests/indexed_trace_access/test_air_plonky3.rs index b01cc0eaa..4c40c296f 100644 --- a/air-script/tests/indexed_trace_access/test_air_plonky3.rs +++ b/air-script/tests/indexed_trace_access/test_air_plonky3.rs @@ -13,8 +13,8 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, indexed_trace_access::indexed_trace_access_plonky3::{NUM_COLUMNS, TraceAccessAir}, }; @@ -54,4 +54,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, TraceAccessAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, TraceAccessAir); diff --git a/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs b/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs index 02c938d1e..eba358ffc 100644 --- a/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs +++ b/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 2; @@ -21,25 +21,35 @@ impl BaseAirWithPublicValues for ListComprehensionAir { } } -impl BaseAirWithPeriodicColumns for ListComprehensionAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for ListComprehensionAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for ListComprehensionAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); - builder.assert_zero::<_>(main_current[0].clone().into() + main_current[1].clone().into().double() - AB::Expr::from_u64(3)); - builder.assert_zero::<_>(main_current[0].clone().into().double() + main_current[1].clone().into() * AB::Expr::from_u64(3) - AB::Expr::from_u64(5)); - builder.assert_zero::<_>(main_current[0].clone().into() * AB::Expr::from_u64(3) + main_current[1].clone().into() * AB::Expr::from_u64(4) - AB::Expr::from_u64(7)); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); + builder.assert_zero_ext::<_>(main_current[0].clone().into() + main_current[1].clone().into().double() - AB::Expr::from_u64(3)); + builder.assert_zero_ext::<_>(main_current[0].clone().into().double() + main_current[1].clone().into() * AB::Expr::from_u64(3) - AB::Expr::from_u64(5)); + builder.assert_zero_ext::<_>(main_current[0].clone().into() * AB::Expr::from_u64(3) + main_current[1].clone().into() * AB::Expr::from_u64(4) - AB::Expr::from_u64(7)); + } +} + +impl Air for ListComprehensionAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/list_comprehension/list_comprehension_plonky3.rs b/air-script/tests/list_comprehension/list_comprehension_plonky3.rs index 9456c4066..b42758fb2 100644 --- a/air-script/tests/list_comprehension/list_comprehension_plonky3.rs +++ b/air-script/tests/list_comprehension/list_comprehension_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 16; @@ -21,28 +21,38 @@ impl BaseAirWithPublicValues for ListComprehensionAir { } } -impl BaseAirWithPeriodicColumns for ListComprehensionAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for ListComprehensionAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for ListComprehensionAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[10].clone().into()); - builder.assert_zero::<_>(main_current[0].clone().into() - main_current[2].clone().into()); - builder.assert_zero::<_>(main_current[4].clone().into() - main_current[0].clone().into() * AB::Expr::from_u64(8) * main_current[11].clone().into()); - builder.when_transition().assert_zero::<_>(main_current[4].clone().into() - main_current[0].clone().into() * (main_next[8].clone().into() - main_next[12].clone().into())); - builder.assert_zero::<_>(main_current[6].clone().into() - main_current[0].clone().into() * (main_current[9].clone().into() - main_current[14].clone().into())); - builder.assert_zero::<_>(main_current[1].clone().into() - (main_current[5].clone().into() - main_current[8].clone().into() - main_current[12].clone().into() + AB::Expr::from_u64(10) + main_current[6].clone().into() - main_current[9].clone().into() - main_current[13].clone().into() + AB::Expr::from_u64(20) + main_current[7].clone().into() - main_current[10].clone().into() - main_current[14].clone().into())); - builder.assert_zero::<_>(main_current[14].clone().into() - AB::Expr::from_u64(10)); + builder.when_first_row().assert_zero_ext::<_>(main_current[10].clone().into()); + builder.assert_zero_ext::<_>(main_current[0].clone().into() - main_current[2].clone().into()); + builder.assert_zero_ext::<_>(main_current[4].clone().into() - main_current[0].clone().into() * AB::Expr::from_u64(8) * main_current[11].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_current[4].clone().into() - main_current[0].clone().into() * (main_next[8].clone().into() - main_next[12].clone().into())); + builder.assert_zero_ext::<_>(main_current[6].clone().into() - main_current[0].clone().into() * (main_current[9].clone().into() - main_current[14].clone().into())); + builder.assert_zero_ext::<_>(main_current[1].clone().into() - (main_current[5].clone().into() - main_current[8].clone().into() - main_current[12].clone().into() + AB::Expr::from_u64(10) + main_current[6].clone().into() - main_current[9].clone().into() - main_current[13].clone().into() + AB::Expr::from_u64(20) + main_current[7].clone().into() - main_current[10].clone().into() - main_current[14].clone().into())); + builder.assert_zero_ext::<_>(main_current[14].clone().into() - AB::Expr::from_u64(10)); + } +} + +impl Air for ListComprehensionAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/list_comprehension/test_air_plonky3.rs b/air-script/tests/list_comprehension/test_air_plonky3.rs index 7cec4aeed..b02c359eb 100644 --- a/air-script/tests/list_comprehension/test_air_plonky3.rs +++ b/air-script/tests/list_comprehension/test_air_plonky3.rs @@ -13,8 +13,8 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, list_comprehension::list_comprehension_plonky3::{ListComprehensionAir, NUM_COLUMNS}, }; @@ -94,4 +94,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, ListComprehensionAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, ListComprehensionAir); diff --git a/air-script/tests/list_folding/list_folding_plonky3.rs b/air-script/tests/list_folding/list_folding_plonky3.rs index 48538e7e3..0e63eb920 100644 --- a/air-script/tests/list_folding/list_folding_plonky3.rs +++ b/air-script/tests/list_folding/list_folding_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 17; @@ -21,26 +21,36 @@ impl BaseAirWithPublicValues for ListFoldingAir { } } -impl BaseAirWithPeriodicColumns for ListFoldingAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for ListFoldingAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for ListFoldingAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[11].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[5].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); - builder.when_transition().assert_zero::<_>(main_next[6].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); - builder.when_transition().assert_zero::<_>(main_next[7].clone().into() - (main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + (main_current[9].clone().into() + main_current[13].clone().into()) * (main_current[10].clone().into() + main_current[14].clone().into()) * (main_current[11].clone().into() + main_current[15].clone().into()) * (main_current[12].clone().into() + main_current[16].clone().into()))); - builder.when_transition().assert_zero::<_>(main_next[8].clone().into() - (main_current[1].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into())); + builder.when_first_row().assert_zero_ext::<_>(main_current[11].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[5].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); + builder.when_transition().assert_zero_ext::<_>(main_next[6].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); + builder.when_transition().assert_zero_ext::<_>(main_next[7].clone().into() - (main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + (main_current[9].clone().into() + main_current[13].clone().into()) * (main_current[10].clone().into() + main_current[14].clone().into()) * (main_current[11].clone().into() + main_current[15].clone().into()) * (main_current[12].clone().into() + main_current[16].clone().into()))); + builder.when_transition().assert_zero_ext::<_>(main_next[8].clone().into() - (main_current[1].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into())); + } +} + +impl Air for ListFoldingAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/list_folding/test_air_plonky3.rs b/air-script/tests/list_folding/test_air_plonky3.rs index 83d82e10d..6c6300eba 100644 --- a/air-script/tests/list_folding/test_air_plonky3.rs +++ b/air-script/tests/list_folding/test_air_plonky3.rs @@ -13,8 +13,8 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, list_folding::list_folding_plonky3::{ListFoldingAir, NUM_COLUMNS}, }; @@ -97,4 +97,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, ListFoldingAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, ListFoldingAir); diff --git a/air-script/tests/periodic_columns/periodic_columns_plonky3.rs b/air-script/tests/periodic_columns/periodic_columns_plonky3.rs index 953454085..a61edaf06 100644 --- a/air-script/tests/periodic_columns/periodic_columns_plonky3.rs +++ b/air-script/tests/periodic_columns/periodic_columns_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 3; @@ -21,26 +21,36 @@ impl BaseAirWithPublicValues for PeriodicColumnsAir { } } -impl BaseAirWithPeriodicColumns for PeriodicColumnsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for PeriodicColumnsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ vec![F::from_u64(1), F::from_u64(0), F::from_u64(0), F::from_u64(0)], vec![F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(0)], ] } -} -impl Air for PeriodicColumnsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); - builder.assert_zero::<_>(periodic_values[0].into() * (main_current[1].clone().into() + main_current[2].clone().into())); - builder.when_transition().assert_zero::<_>(periodic_values[1].into() * (main_next[0].clone().into() - main_current[0].clone().into())); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); + builder.assert_zero_ext::<_>(periodic_values[0].into() * (main_current[1].clone().into() + main_current[2].clone().into())); + builder.when_transition().assert_zero_ext::<_>(periodic_values[1].into() * (main_next[0].clone().into() - main_current[0].clone().into())); + } +} + +impl Air for PeriodicColumnsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/periodic_columns/test_air_plonky3.rs b/air-script/tests/periodic_columns/test_air_plonky3.rs index 6b7b9acce..2f5c74bfa 100644 --- a/air-script/tests/periodic_columns/test_air_plonky3.rs +++ b/air-script/tests/periodic_columns/test_air_plonky3.rs @@ -13,8 +13,8 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, periodic_columns::periodic_columns_plonky3::{NUM_COLUMNS, PeriodicColumnsAir}, }; @@ -55,4 +55,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, PeriodicColumnsAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, PeriodicColumnsAir); diff --git a/air-script/tests/pub_inputs/pub_inputs_plonky3.rs b/air-script/tests/pub_inputs/pub_inputs_plonky3.rs index 1c0829516..2a70abe19 100644 --- a/air-script/tests/pub_inputs/pub_inputs_plonky3.rs +++ b/air-script/tests/pub_inputs/pub_inputs_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 4; @@ -21,30 +21,40 @@ impl BaseAirWithPublicValues for PubInputsAir { } } -impl BaseAirWithPeriodicColumns for PubInputsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for PubInputsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for PubInputsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into() - public_values[8].into()); - builder.when_first_row().assert_zero::<_>(main_current[1].clone().into() - public_values[9].into()); - builder.when_first_row().assert_zero::<_>(main_current[2].clone().into() - public_values[10].into()); - builder.when_first_row().assert_zero::<_>(main_current[3].clone().into() - public_values[11].into()); - builder.when_last_row().assert_zero::<_>(main_current[0].clone().into() - public_values[12].into()); - builder.when_last_row().assert_zero::<_>(main_current[1].clone().into() - public_values[13].into()); - builder.when_last_row().assert_zero::<_>(main_current[2].clone().into() - public_values[14].into()); - builder.when_last_row().assert_zero::<_>(main_current[3].clone().into() - public_values[15].into()); - builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - (main_current[1].clone().into() + main_current[2].clone().into())); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into() - public_values[8].into()); + builder.when_first_row().assert_zero_ext::<_>(main_current[1].clone().into() - public_values[9].into()); + builder.when_first_row().assert_zero_ext::<_>(main_current[2].clone().into() - public_values[10].into()); + builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into() - public_values[11].into()); + builder.when_last_row().assert_zero_ext::<_>(main_current[0].clone().into() - public_values[12].into()); + builder.when_last_row().assert_zero_ext::<_>(main_current[1].clone().into() - public_values[13].into()); + builder.when_last_row().assert_zero_ext::<_>(main_current[2].clone().into() - public_values[14].into()); + builder.when_last_row().assert_zero_ext::<_>(main_current[3].clone().into() - public_values[15].into()); + builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - (main_current[1].clone().into() + main_current[2].clone().into())); + } +} + +impl Air for PubInputsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/pub_inputs/test_air_plonky3.rs b/air-script/tests/pub_inputs/test_air_plonky3.rs index 71343872e..5b5ffbcef 100644 --- a/air-script/tests/pub_inputs/test_air_plonky3.rs +++ b/air-script/tests/pub_inputs/test_air_plonky3.rs @@ -13,8 +13,8 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, pub_inputs::pub_inputs_plonky3::{NUM_COLUMNS, PubInputsAir}, }; @@ -58,4 +58,4 @@ fn generate_inputs() -> Vec { vec![0; 32] } -generate_air_plonky3_test!(test_air_plonky3, PubInputsAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, PubInputsAir); diff --git a/air-script/tests/selectors/selectors_combine_complex_plonky3.rs b/air-script/tests/selectors/selectors_combine_complex_plonky3.rs index fee0da529..f6e1a97f2 100644 --- a/air-script/tests/selectors/selectors_combine_complex_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_complex_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 6; @@ -21,25 +21,35 @@ impl BaseAirWithPublicValues for SelectorsAir { } } -impl BaseAirWithPeriodicColumns for SelectorsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for SelectorsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 3; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for SelectorsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[5].clone().into()); - builder.assert_zero::<_>((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * (main_current[3].clone().into() - AB::Expr::from_u64(16)) + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(5))); - builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(5)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(4))); - builder.assert_zero::<_>(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(20)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(31))); + builder.when_first_row().assert_zero_ext::<_>(main_current[5].clone().into()); + builder.assert_zero_ext::<_>((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * (main_current[3].clone().into() - AB::Expr::from_u64(16)) + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(5))); + builder.assert_zero_ext::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(5)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(4))); + builder.assert_zero_ext::<_>(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(20)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(31))); + } +} + +impl Air for SelectorsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_combine_simple_plonky3.rs b/air-script/tests/selectors/selectors_combine_simple_plonky3.rs index 5bee29c5a..8732ca151 100644 --- a/air-script/tests/selectors/selectors_combine_simple_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_simple_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 4; @@ -21,24 +21,34 @@ impl BaseAirWithPublicValues for SelectorsAir { } } -impl BaseAirWithPeriodicColumns for SelectorsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for SelectorsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for SelectorsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[3].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[1].clone().into() - main_current[2].clone().into()); - builder.when_transition().assert_zero::<_>(main_current[3].clone().into() * (main_next[0].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())) + (AB::Expr::ONE - main_current[3].clone().into()) * (main_next[0].clone().into() - main_current[0].clone().into() * main_current[1].clone().into())); + builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[1].clone().into() - main_current[2].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_current[3].clone().into() * (main_next[0].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())) + (AB::Expr::ONE - main_current[3].clone().into()) * (main_next[0].clone().into() - main_current[0].clone().into() * main_current[1].clone().into())); + } +} + +impl Air for SelectorsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs b/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs index cd222b9b1..0721984ca 100644 --- a/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 6; @@ -21,25 +21,35 @@ impl BaseAirWithPublicValues for SelectorsAir { } } -impl BaseAirWithPeriodicColumns for SelectorsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for SelectorsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for SelectorsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[5].clone().into()); - builder.assert_zero::<_>((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * main_current[3].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(8))); - builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(8)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(2))); - builder.assert_zero::<_>(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(4)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(6))); + builder.when_first_row().assert_zero_ext::<_>(main_current[5].clone().into()); + builder.assert_zero_ext::<_>((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * main_current[3].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(8))); + builder.assert_zero_ext::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(8)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(2))); + builder.assert_zero_ext::<_>(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(4)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(6))); + } +} + +impl Air for SelectorsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_plonky3.rs b/air-script/tests/selectors/selectors_plonky3.rs index 1c9c27a7e..c6c27edfe 100644 --- a/air-script/tests/selectors/selectors_plonky3.rs +++ b/air-script/tests/selectors/selectors_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 4; @@ -21,24 +21,34 @@ impl BaseAirWithPublicValues for SelectorsAir { } } -impl BaseAirWithPeriodicColumns for SelectorsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for SelectorsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for SelectorsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[3].clone().into()); - builder.when_transition().assert_zero::<_>(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); - builder.when_transition().assert_zero::<_>(main_current[0].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); + builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_current[0].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); + } +} + +impl Air for SelectorsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs b/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs index 2f59c7abb..d9cb2bb25 100644 --- a/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs +++ b/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 4; @@ -21,24 +21,34 @@ impl BaseAirWithPublicValues for SelectorsAir { } } -impl BaseAirWithPeriodicColumns for SelectorsAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for SelectorsAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for SelectorsAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[3].clone().into()); - builder.when_transition().assert_zero::<_>(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); - builder.when_transition().assert_zero::<_>(main_current[1].clone().into() * main_current[2].clone().into() * main_current[0].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); + builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_current[1].clone().into() * main_current[2].clone().into() * main_current[0].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); + } +} + +impl Air for SelectorsAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/selectors/test_air_plonky3.rs b/air-script/tests/selectors/test_air_plonky3.rs index 289939f0e..151323197 100644 --- a/air-script/tests/selectors/test_air_plonky3.rs +++ b/air-script/tests/selectors/test_air_plonky3.rs @@ -13,8 +13,8 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, selectors::selectors_with_evaluators_plonky3::{NUM_COLUMNS, SelectorsAir}, }; @@ -58,4 +58,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, SelectorsAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, SelectorsAir); diff --git a/air-script/tests/system/system_plonky3.rs b/air-script/tests/system/system_plonky3.rs index b4c330ab3..f1c1f2805 100644 --- a/air-script/tests/system/system_plonky3.rs +++ b/air-script/tests/system/system_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 3; @@ -21,23 +21,33 @@ impl BaseAirWithPublicValues for SystemAir { } } -impl BaseAirWithPeriodicColumns for SystemAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for SystemAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for SystemAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[0].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); + builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); + } +} + +impl Air for SystemAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/system/test_air_plonky3.rs b/air-script/tests/system/test_air_plonky3.rs index 9c0eb5004..5bf16d4e8 100644 --- a/air-script/tests/system/test_air_plonky3.rs +++ b/air-script/tests/system/test_air_plonky3.rs @@ -13,8 +13,8 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, system::system_plonky3::{NUM_COLUMNS, SystemAir}, }; @@ -55,4 +55,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, SystemAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, SystemAir); diff --git a/air-script/tests/trace_col_groups/test_air_plonky3.rs b/air-script/tests/trace_col_groups/test_air_plonky3.rs index b12ab3ac7..56e5cdd7c 100644 --- a/air-script/tests/trace_col_groups/test_air_plonky3.rs +++ b/air-script/tests/trace_col_groups/test_air_plonky3.rs @@ -13,8 +13,8 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, trace_col_groups::trace_col_groups_plonky3::{NUM_COLUMNS, TraceColGroupAir}, }; @@ -73,4 +73,4 @@ fn generate_inputs() -> Vec { vec![1; 16] } -generate_air_plonky3_test!(test_air_plonky3, TraceColGroupAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, TraceColGroupAir); diff --git a/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs b/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs index f80168286..78ee3f372 100644 --- a/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs +++ b/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 9; @@ -21,24 +21,34 @@ impl BaseAirWithPublicValues for TraceColGroupAir { } } -impl BaseAirWithPeriodicColumns for TraceColGroupAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for TraceColGroupAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ ] } -} -impl Air for TraceColGroupAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[8].clone().into()); - builder.when_transition().assert_zero::<_>(main_next[2].clone().into() - (main_current[2].clone().into() + AB::Expr::ONE)); - builder.when_transition().assert_zero::<_>(main_next[1].clone().into() - (main_current[1].clone().into() - AB::Expr::ONE)); + builder.when_first_row().assert_zero_ext::<_>(main_current[8].clone().into()); + builder.when_transition().assert_zero_ext::<_>(main_next[2].clone().into() - (main_current[2].clone().into() + AB::Expr::ONE)); + builder.when_transition().assert_zero_ext::<_>(main_next[1].clone().into() - (main_current[1].clone().into() - AB::Expr::ONE)); + } +} + +impl Air for TraceColGroupAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/variables/test_air_plonky3.rs b/air-script/tests/variables/test_air_plonky3.rs index 8296f2197..db94f1c30 100644 --- a/air-script/tests/variables/test_air_plonky3.rs +++ b/air-script/tests/variables/test_air_plonky3.rs @@ -13,8 +13,8 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - generate_air_plonky3_test, - helpers::check_constraints_with_periodic_columns, + generate_air_plonky3_test_with_airscript_traits, + helpers::check_constraints_with_airscript_traits, variables::variables_plonky3::{NUM_COLUMNS, VariablesAir}, }; @@ -58,4 +58,4 @@ fn generate_inputs() -> Vec { vec![1; 32] } -generate_air_plonky3_test!(test_air_plonky3, VariablesAir); +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, VariablesAir); diff --git a/air-script/tests/variables/variables_plonky3.rs b/air-script/tests/variables/variables_plonky3.rs index acd8472df..d9efbf68c 100644 --- a/air-script/tests/variables/variables_plonky3.rs +++ b/air-script/tests/variables/variables_plonky3.rs @@ -1,7 +1,7 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir, BaseAirWithPublicValues}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; use p3_matrix::Matrix; -use p3_field::PrimeCharacteristicRing; -use crate::helpers::{AirBuilderWithPeriodicColumns, BaseAirWithPeriodicColumns}; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::helpers::{AirScriptAir, AirScriptBuilder}; pub const NUM_COLUMNS: usize = 4; @@ -21,28 +21,38 @@ impl BaseAirWithPublicValues for VariablesAir { } } -impl BaseAirWithPeriodicColumns for VariablesAir { - fn get_periodic_columns(&self) -> Vec> { +impl AirScriptAir for VariablesAir { + const MAIN_WIDTH: usize = NUM_COLUMNS; + const AUX_WIDTH: usize = 0; + const PERIOD: usize = 0; + const NUM_ALPHA_CHALLENGES: usize = 0; + fn periodic_table(&self) -> Vec> { vec![ vec![F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(0)], ] } -} -impl Air for VariablesAir { - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: AirScriptBuilder, + { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_columns(); + let periodic_values = builder.periodic_evals().to_vec(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero::<_>(main_current[1].clone().into()); - builder.when_last_row().assert_zero::<_>(main_current[1].clone().into() - AB::Expr::ONE); - builder.assert_zero::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); - builder.when_transition().assert_zero::<_>(periodic_values[0].into() * (main_next[0].clone().into() - main_current[0].clone().into())); - builder.assert_zero::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[3].clone().into() - main_current[1].clone().into() - main_current[2].clone().into()) - (AB::Expr::from_u64(6) - (AB::Expr::from_u64(7) - main_current[0].clone().into()))); - builder.when_transition().assert_zero::<_>(main_current[0].clone().into() * (main_current[3].clone().into() - main_current[1].clone().into() * main_current[2].clone().into()) - (AB::Expr::ONE - main_next[0].clone().into())); + builder.when_first_row().assert_zero_ext::<_>(main_current[1].clone().into()); + builder.when_last_row().assert_zero_ext::<_>(main_current[1].clone().into() - AB::Expr::ONE); + builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.when_transition().assert_zero_ext::<_>(periodic_values[0].into() * (main_next[0].clone().into() - main_current[0].clone().into())); + builder.assert_zero_ext::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[3].clone().into() - main_current[1].clone().into() - main_current[2].clone().into()) - (AB::Expr::from_u64(6) - (AB::Expr::from_u64(7) - main_current[0].clone().into()))); + builder.when_transition().assert_zero_ext::<_>(main_current[0].clone().into() * (main_current[3].clone().into() - main_current[1].clone().into() * main_current[2].clone().into()) - (AB::Expr::ONE - main_next[0].clone().into())); + } +} + +impl Air for VariablesAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); } } \ No newline at end of file diff --git a/codegen/plonky3/src/air/boundary_constraints.rs b/codegen/plonky3/src/air/boundary_constraints.rs index 4c8fd0047..79b0278a2 100644 --- a/codegen/plonky3/src/air/boundary_constraints.rs +++ b/codegen/plonky3/src/air/boundary_constraints.rs @@ -12,10 +12,10 @@ pub(super) fn add_main_boundary_constraints(eval_func: &mut Function, ir: &Air) let assertion = match constraint.domain() { air_ir::ConstraintDomain::FirstRow => { - format!("builder.when_first_row().assert_zero::<_>({expr_root_string});") + format!("builder.when_first_row().assert_zero_ext::<_>({expr_root_string});") }, air_ir::ConstraintDomain::LastRow => { - format!("builder.when_last_row().assert_zero::<_>({expr_root_string});") + format!("builder.when_last_row().assert_zero_ext::<_>({expr_root_string});") }, _ => unreachable!("Boundary constraints can only be applied to the first or last row"), }; diff --git a/codegen/plonky3/src/air/integrity_constraints.rs b/codegen/plonky3/src/air/integrity_constraints.rs index 0d79dfcf0..07e6a396c 100644 --- a/codegen/plonky3/src/air/integrity_constraints.rs +++ b/codegen/plonky3/src/air/integrity_constraints.rs @@ -12,9 +12,9 @@ pub(super) fn add_main_integrity_constraints(eval_func: &mut Function, ir: &Air) // If the constraint is a transition constraint (depends on the next row), we do not // evaluate it in the last row, with the `when_transition` method. let assertion = if let ConstraintDomain::EveryFrame(_) = constraint.domain() { - format!("builder.when_transition().assert_zero::<_>({expr_root_string});") + format!("builder.when_transition().assert_zero_ext::<_>({expr_root_string});") } else { - format!("builder.assert_zero::<_>({expr_root_string});") + format!("builder.assert_zero_ext::<_>({expr_root_string});") }; eval_func.line(assertion); diff --git a/codegen/plonky3/src/air/mod.rs b/codegen/plonky3/src/air/mod.rs index a11287f87..608b25f15 100644 --- a/codegen/plonky3/src/air/mod.rs +++ b/codegen/plonky3/src/air/mod.rs @@ -22,8 +22,11 @@ pub(super) fn add_air(scope: &mut Scope, ir: &Air) { // add the Air struct and its base implementation. add_air_struct(scope, ir, name); + // add AirScriptAir trait implementation for the provided AirIR. + add_air_script_trait(scope, ir, name); + // add Plonky3 AirBuilder trait implementation for the provided AirIR. - add_air_trait(scope, ir, name); + add_air_trait(scope, name); } /// Updates the provided scope with a custom Air struct. @@ -49,42 +52,47 @@ fn add_air_struct(scope: &mut Scope, ir: &Air, name: &str) { .arg_ref_self() .ret("usize") .line("NUM_PUBLIC_VALUES"); +} - // add the custom BaseAirWithPeriodicColumns implementation block - let base_air_with_periodic_columns_impl = scope - .new_impl(name) - .generic("F: PrimeCharacteristicRing") - .impl_trait("BaseAirWithPeriodicColumns"); - let base_air_with_periodic_columns_impl_func = base_air_with_periodic_columns_impl - .new_fn("get_periodic_columns") +fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { + // add the custom AirScriptAir implementation block + let air_script_impl = scope.new_impl(name).generic("F: Field").impl_trait("AirScriptAir"); + air_script_impl.associate_const("MAIN_WIDTH", "usize", "NUM_COLUMNS", ""); + air_script_impl.associate_const("AUX_WIDTH", "usize", "0", ""); + air_script_impl.associate_const("PERIOD", "usize", "0", ""); + let num_alpha_challenges = ir.num_random_values; + air_script_impl.associate_const( + "NUM_ALPHA_CHALLENGES", + "usize", + format!("{num_alpha_challenges}"), + "", + ); + + let periodic_table_func = air_script_impl + .new_fn("periodic_table") .arg_ref_self() + //.ret("&'static [&'static [Self::F]]"); .ret("Vec>"); - base_air_with_periodic_columns_impl_func.line("vec!["); - + periodic_table_func.line("vec!["); for col in ir.periodic_columns() { let values_str = col.values .iter() .map(|v| format!("F::from_u64({v})")) // or use a custom formatter if needed .collect::>() .join(", "); - base_air_with_periodic_columns_impl_func.line(format!(" vec![{values_str}],")); + periodic_table_func.line(format!(" vec![{values_str}],")); } - base_air_with_periodic_columns_impl_func.line("]"); -} + periodic_table_func.line("]"); -/// Updates the provided scope with the custom Air struct and an Air trait implementation based on -/// the provided AirIR. -fn add_air_trait(scope: &mut Scope, ir: &Air, name: &str) { - // add the implementation block for the Air trait. - let air_impl = scope - .new_impl(name) - .generic("AB: AirBuilderWithPublicValues + AirBuilderWithPeriodicColumns") - .impl_trait("Air"); - - let eval_func = air_impl.new_fn("eval").arg_ref_self().arg("builder", "&mut AB"); + let eval_func = air_script_impl + .new_fn("eval") + .generic("AB") + .arg_ref_self() + .arg("builder", "&mut AB") + .bound("AB", "AirScriptBuilder"); eval_func.line("let main = builder.main();"); eval_func.line("let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect(\"Wrong number of public values\");"); - eval_func.line("let periodic_values = builder.periodic_columns();"); + eval_func.line("let periodic_values = builder.periodic_evals().to_vec();"); eval_func.line("let (main_current, main_next) = ("); eval_func.line(" main.row_slice(0).unwrap(),"); eval_func.line(" main.row_slice(1).unwrap(),"); @@ -94,3 +102,13 @@ fn add_air_trait(scope: &mut Scope, ir: &Air, name: &str) { add_main_integrity_constraints(eval_func, ir); } + +/// Updates the provided scope with the custom Air struct and an Air trait implementation based on +/// the provided AirIR. +fn add_air_trait(scope: &mut Scope, name: &str) { + // add the implementation block for the Air trait. + let air_impl = scope.new_impl(name).generic("AB: AirScriptBuilder").impl_trait("Air"); + + let eval_func = air_impl.new_fn("eval").arg_ref_self().arg("builder", "&mut AB"); + eval_func.line(">::eval(self, builder);"); +} diff --git a/codegen/plonky3/src/imports.rs b/codegen/plonky3/src/imports.rs index 28ef3501b..f0200360b 100644 --- a/codegen/plonky3/src/imports.rs +++ b/codegen/plonky3/src/imports.rs @@ -4,12 +4,12 @@ use super::Scope; pub(super) fn add_imports(scope: &mut Scope) { // add plonky3 imports scope.import("p3_air", "Air"); - scope.import("p3_air", "AirBuilder"); - scope.import("p3_air", "AirBuilderWithPublicValues"); scope.import("p3_air", "BaseAir"); scope.import("p3_air", "BaseAirWithPublicValues"); + scope.import("p3_air", "ExtensionBuilder"); scope.import("p3_matrix", "Matrix"); + scope.import("p3_field", "Field"); scope.import("p3_field", "PrimeCharacteristicRing"); - scope.import("crate::helpers", "AirBuilderWithPeriodicColumns"); - scope.import("crate::helpers", "BaseAirWithPeriodicColumns"); + scope.import("crate::helpers", "AirScriptAir"); + scope.import("crate::helpers", "AirScriptBuilder"); } From 2b44fbf63f239bc8ac730754dfe29d20dd8a7943 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 6 Nov 2025 08:39:41 +0100 Subject: [PATCH 04/22] refactor: Make AirScriptAir dyn compatible, clean code --- air-script/tests/binary/binary_plonky3.rs | 34 +++--- air-script/tests/binary/test_air_plonky3.rs | 8 +- air-script/tests/bitwise/bitwise_plonky3.rs | 31 +++--- air-script/tests/bitwise/test_air_plonky3.rs | 8 +- .../tests/buses/buses_complex_plonky3.rs | 34 +++--- .../tests/buses/buses_simple_plonky3.rs | 34 +++--- .../buses_varlen_boundary_both_plonky3.rs | 34 +++--- .../buses_varlen_boundary_first_plonky3.rs | 34 +++--- .../buses_varlen_boundary_last_plonky3.rs | 34 +++--- air-script/tests/buses/test_air_plonky3.rs | 8 +- .../computed_indices_complex_plonky3.rs | 34 +++--- .../computed_indices_simple_plonky3.rs | 34 +++--- .../constant_in_range_plonky3.rs | 34 +++--- .../constant_in_range/test_air_plonky3.rs | 8 +- .../tests/constants/constants_plonky3.rs | 34 +++--- .../tests/constants/test_air_plonky3.rs | 8 +- .../constraint_comprehension_plonky3.rs | 34 +++--- .../test_air_plonky3.rs | 8 +- .../tests/evaluators/evaluators_plonky3.rs | 34 +++--- .../tests/evaluators/test_air_plonky3.rs | 8 +- .../tests/fibonacci/fibonacci_plonky3.rs | 34 +++--- .../tests/fibonacci/test_air_plonky3.rs | 8 +- .../functions/functions_complex_plonky3.rs | 34 +++--- .../functions/functions_simple_plonky3.rs | 34 +++--- .../tests/functions/test_air_plonky3.rs | 8 +- air-script/tests/helpers/plonky3_traits.rs | 28 ++--- .../indexed_trace_access_plonky3.rs | 34 +++--- .../indexed_trace_access/test_air_plonky3.rs | 8 +- .../list_comprehension_nested_plonky3.rs | 34 +++--- .../list_comprehension_plonky3.rs | 34 +++--- .../list_comprehension/test_air_plonky3.rs | 8 +- .../list_folding/list_folding_plonky3.rs | 34 +++--- .../tests/list_folding/test_air_plonky3.rs | 8 +- .../periodic_columns_plonky3.rs | 31 +++--- .../periodic_columns/test_air_plonky3.rs | 8 +- .../tests/pub_inputs/pub_inputs_plonky3.rs | 34 +++--- .../tests/pub_inputs/test_air_plonky3.rs | 8 +- .../selectors_combine_complex_plonky3.rs | 34 +++--- .../selectors_combine_simple_plonky3.rs | 34 +++--- ...ombine_with_list_comprehensions_plonky3.rs | 34 +++--- .../tests/selectors/selectors_plonky3.rs | 34 +++--- .../selectors_with_evaluators_plonky3.rs | 34 +++--- .../tests/selectors/test_air_plonky3.rs | 8 +- air-script/tests/system/system_plonky3.rs | 34 +++--- air-script/tests/system/test_air_plonky3.rs | 8 +- .../trace_col_groups/test_air_plonky3.rs | 8 +- .../trace_col_groups_plonky3.rs | 34 +++--- .../tests/variables/test_air_plonky3.rs | 8 +- .../tests/variables/variables_plonky3.rs | 31 +++--- codegen/plonky3/src/air/mod.rs | 105 ++++++++++++------ 50 files changed, 723 insertions(+), 565 deletions(-) diff --git a/air-script/tests/binary/binary_plonky3.rs b/air-script/tests/binary/binary_plonky3.rs index 1660f5e69..956f773a8 100644 --- a/air-script/tests/binary/binary_plonky3.rs +++ b/air-script/tests/binary/binary_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 2; - +pub const MAIN_WIDTH: usize = 2; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct BinaryAir; impl BaseAir for BinaryAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for BinaryAir { } } -impl AirScriptAir for BinaryAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for BinaryAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -49,6 +53,6 @@ impl AirScriptAir for BinaryAir { impl Air for BinaryAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/binary/test_air_plonky3.rs b/air-script/tests/binary/test_air_plonky3.rs index 266a003e1..efca75dcf 100644 --- a/air-script/tests/binary/test_air_plonky3.rs +++ b/air-script/tests/binary/test_air_plonky3.rs @@ -13,20 +13,20 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - binary::binary_plonky3::{BinaryAir, NUM_COLUMNS}, + binary::binary_plonky3::{BinaryAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/bitwise/bitwise_plonky3.rs b/air-script/tests/bitwise/bitwise_plonky3.rs index 093b396e6..332dbb70f 100644 --- a/air-script/tests/bitwise/bitwise_plonky3.rs +++ b/air-script/tests/bitwise/bitwise_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 14; - +pub const MAIN_WIDTH: usize = 14; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 2; +pub const PERIOD: usize = 8; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct BitwiseAir; impl BaseAir for BitwiseAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,11 +24,15 @@ impl BaseAirWithPublicValues for BitwiseAir { } } -impl AirScriptAir for BitwiseAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for BitwiseAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { vec![ vec![F::from_u64(1), F::from_u64(0), F::from_u64(0), F::from_u64(0), F::from_u64(0), F::from_u64(0), F::from_u64(0), F::from_u64(0)], @@ -33,12 +40,10 @@ impl AirScriptAir for BitwiseAir { ] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -66,6 +71,6 @@ impl AirScriptAir for BitwiseAir { impl Air for BitwiseAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/bitwise/test_air_plonky3.rs b/air-script/tests/bitwise/test_air_plonky3.rs index 94b5aa172..d88fa475a 100644 --- a/air-script/tests/bitwise/test_air_plonky3.rs +++ b/air-script/tests/bitwise/test_air_plonky3.rs @@ -13,20 +13,20 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - bitwise::bitwise_plonky3::{BitwiseAir, NUM_COLUMNS}, + bitwise::bitwise_plonky3::{BitwiseAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/buses/buses_complex_plonky3.rs b/air-script/tests/buses/buses_complex_plonky3.rs index 710e04cd2..43978f9df 100644 --- a/air-script/tests/buses/buses_complex_plonky3.rs +++ b/air-script/tests/buses/buses_complex_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 5; - +pub const MAIN_WIDTH: usize = 5; +pub const AUX_WIDTH: usize = 2; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; +pub const NUM_ALPHA_CHALLENGES: usize = 4; pub struct BusesAir; impl BaseAir for BusesAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for BusesAir { } } -impl AirScriptAir for BusesAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 4; +impl> AirScriptAir for BusesAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -49,6 +53,6 @@ impl AirScriptAir for BusesAir { impl Air for BusesAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/buses/buses_simple_plonky3.rs b/air-script/tests/buses/buses_simple_plonky3.rs index 5b641ad49..c06f26e2b 100644 --- a/air-script/tests/buses/buses_simple_plonky3.rs +++ b/air-script/tests/buses/buses_simple_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 1; - +pub const MAIN_WIDTH: usize = 1; +pub const AUX_WIDTH: usize = 2; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; +pub const NUM_ALPHA_CHALLENGES: usize = 3; pub struct BusesAir; impl BaseAir for BusesAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for BusesAir { } } -impl AirScriptAir for BusesAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 3; +impl> AirScriptAir for BusesAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -46,6 +50,6 @@ impl AirScriptAir for BusesAir { impl Air for BusesAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs b/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs index 60627dc6c..9af5f0402 100644 --- a/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs +++ b/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 1; - +pub const MAIN_WIDTH: usize = 1; +pub const AUX_WIDTH: usize = 2; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 6; +pub const NUM_ALPHA_CHALLENGES: usize = 3; pub struct BusesAir; impl BaseAir for BusesAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for BusesAir { } } -impl AirScriptAir for BusesAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 3; +impl> AirScriptAir for BusesAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -46,6 +50,6 @@ impl AirScriptAir for BusesAir { impl Air for BusesAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs b/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs index 5b641ad49..c06f26e2b 100644 --- a/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs +++ b/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 1; - +pub const MAIN_WIDTH: usize = 1; +pub const AUX_WIDTH: usize = 2; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; +pub const NUM_ALPHA_CHALLENGES: usize = 3; pub struct BusesAir; impl BaseAir for BusesAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for BusesAir { } } -impl AirScriptAir for BusesAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 3; +impl> AirScriptAir for BusesAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -46,6 +50,6 @@ impl AirScriptAir for BusesAir { impl Air for BusesAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs b/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs index 5b641ad49..c06f26e2b 100644 --- a/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs +++ b/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 1; - +pub const MAIN_WIDTH: usize = 1; +pub const AUX_WIDTH: usize = 2; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; +pub const NUM_ALPHA_CHALLENGES: usize = 3; pub struct BusesAir; impl BaseAir for BusesAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for BusesAir { } } -impl AirScriptAir for BusesAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 3; +impl> AirScriptAir for BusesAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -46,6 +50,6 @@ impl AirScriptAir for BusesAir { impl Air for BusesAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/buses/test_air_plonky3.rs b/air-script/tests/buses/test_air_plonky3.rs index 98502069a..fd443caf9 100644 --- a/air-script/tests/buses/test_air_plonky3.rs +++ b/air-script/tests/buses/test_air_plonky3.rs @@ -13,20 +13,20 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - buses::buses_complex_plonky3::{BusesAir, NUM_COLUMNS}, + buses::buses_complex_plonky3::{BusesAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs b/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs index 99b23171c..84f5cf63c 100644 --- a/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs +++ b/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 4; - +pub const MAIN_WIDTH: usize = 4; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct ComputedIndicesAir; impl BaseAir for ComputedIndicesAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for ComputedIndicesAir { } } -impl AirScriptAir for ComputedIndicesAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for ComputedIndicesAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -48,6 +52,6 @@ impl AirScriptAir for ComputedIndicesAir { impl Air for ComputedIndicesAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs b/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs index 00fac14c1..39c53d19c 100644 --- a/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs +++ b/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 8; - +pub const MAIN_WIDTH: usize = 8; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct ComputedIndicesAir; impl BaseAir for ComputedIndicesAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for ComputedIndicesAir { } } -impl AirScriptAir for ComputedIndicesAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for ComputedIndicesAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -55,6 +59,6 @@ impl AirScriptAir for ComputedIndicesAir { impl Air for ComputedIndicesAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/constant_in_range/constant_in_range_plonky3.rs b/air-script/tests/constant_in_range/constant_in_range_plonky3.rs index 5163db980..8b42c19c2 100644 --- a/air-script/tests/constant_in_range/constant_in_range_plonky3.rs +++ b/air-script/tests/constant_in_range/constant_in_range_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 12; - +pub const MAIN_WIDTH: usize = 12; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct ConstantInRangeAir; impl BaseAir for ConstantInRangeAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for ConstantInRangeAir { } } -impl AirScriptAir for ConstantInRangeAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for ConstantInRangeAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -48,6 +52,6 @@ impl AirScriptAir for ConstantInRangeAir { impl Air for ConstantInRangeAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/constant_in_range/test_air_plonky3.rs b/air-script/tests/constant_in_range/test_air_plonky3.rs index d999eafd2..2857f5648 100644 --- a/air-script/tests/constant_in_range/test_air_plonky3.rs +++ b/air-script/tests/constant_in_range/test_air_plonky3.rs @@ -13,20 +13,20 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - constant_in_range::constant_in_range_plonky3::{ConstantInRangeAir, NUM_COLUMNS}, + constant_in_range::constant_in_range_plonky3::{ConstantInRangeAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/constants/constants_plonky3.rs b/air-script/tests/constants/constants_plonky3.rs index 088ab7f88..5828b7d4a 100644 --- a/air-script/tests/constants/constants_plonky3.rs +++ b/air-script/tests/constants/constants_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 7; - +pub const MAIN_WIDTH: usize = 7; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 32; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct ConstantsAir; impl BaseAir for ConstantsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for ConstantsAir { } } -impl AirScriptAir for ConstantsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for ConstantsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -57,6 +61,6 @@ impl AirScriptAir for ConstantsAir { impl Air for ConstantsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/constants/test_air_plonky3.rs b/air-script/tests/constants/test_air_plonky3.rs index 4f6032d7d..5499b69ae 100644 --- a/air-script/tests/constants/test_air_plonky3.rs +++ b/air-script/tests/constants/test_air_plonky3.rs @@ -13,20 +13,20 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - constants::constants_plonky3::{ConstantsAir, NUM_COLUMNS}, + constants::constants_plonky3::{ConstantsAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs b/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs index 22fd4c228..6ab7b74ee 100644 --- a/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs +++ b/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 14; - +pub const MAIN_WIDTH: usize = 14; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct ConstraintComprehensionAir; impl BaseAir for ConstraintComprehensionAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for ConstraintComprehensionAir { } } -impl AirScriptAir for ConstraintComprehensionAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for ConstraintComprehensionAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -51,6 +55,6 @@ impl AirScriptAir for ConstraintComprehensionAir { impl Air for ConstraintComprehensionAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/constraint_comprehension/test_air_plonky3.rs b/air-script/tests/constraint_comprehension/test_air_plonky3.rs index 1753ec70f..e5a1658ca 100644 --- a/air-script/tests/constraint_comprehension/test_air_plonky3.rs +++ b/air-script/tests/constraint_comprehension/test_air_plonky3.rs @@ -14,7 +14,7 @@ use p3_uni_stark::StarkConfig; use crate::{ constraint_comprehension::constraint_comprehension_plonky3::{ - ConstraintComprehensionAir, NUM_COLUMNS, + ConstraintComprehensionAir, MAIN_WIDTH, }, generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, @@ -22,13 +22,13 @@ use crate::{ pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/evaluators/evaluators_plonky3.rs b/air-script/tests/evaluators/evaluators_plonky3.rs index e2d0cdb1c..b74b6b99f 100644 --- a/air-script/tests/evaluators/evaluators_plonky3.rs +++ b/air-script/tests/evaluators/evaluators_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 7; - +pub const MAIN_WIDTH: usize = 7; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct EvaluatorsAir; impl BaseAir for EvaluatorsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for EvaluatorsAir { } } -impl AirScriptAir for EvaluatorsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for EvaluatorsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -57,6 +61,6 @@ impl AirScriptAir for EvaluatorsAir { impl Air for EvaluatorsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/evaluators/test_air_plonky3.rs b/air-script/tests/evaluators/test_air_plonky3.rs index fe22d06d8..891bac58a 100644 --- a/air-script/tests/evaluators/test_air_plonky3.rs +++ b/air-script/tests/evaluators/test_air_plonky3.rs @@ -13,20 +13,20 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - evaluators::evaluators_plonky3::{EvaluatorsAir, NUM_COLUMNS}, + evaluators::evaluators_plonky3::{EvaluatorsAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/fibonacci/fibonacci_plonky3.rs b/air-script/tests/fibonacci/fibonacci_plonky3.rs index f2c5d8aad..baa978c64 100644 --- a/air-script/tests/fibonacci/fibonacci_plonky3.rs +++ b/air-script/tests/fibonacci/fibonacci_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 2; - +pub const MAIN_WIDTH: usize = 2; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 3; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct FibonacciAir; impl BaseAir for FibonacciAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for FibonacciAir { } } -impl AirScriptAir for FibonacciAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for FibonacciAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -51,6 +55,6 @@ impl AirScriptAir for FibonacciAir { impl Air for FibonacciAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/fibonacci/test_air_plonky3.rs b/air-script/tests/fibonacci/test_air_plonky3.rs index 28afeb872..3725fdf9b 100644 --- a/air-script/tests/fibonacci/test_air_plonky3.rs +++ b/air-script/tests/fibonacci/test_air_plonky3.rs @@ -13,20 +13,20 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - fibonacci::fibonacci_plonky3::{FibonacciAir, NUM_COLUMNS}, + fibonacci::fibonacci_plonky3::{FibonacciAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 31; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/functions/functions_complex_plonky3.rs b/air-script/tests/functions/functions_complex_plonky3.rs index 83497ae05..596d2790c 100644 --- a/air-script/tests/functions/functions_complex_plonky3.rs +++ b/air-script/tests/functions/functions_complex_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 17; - +pub const MAIN_WIDTH: usize = 17; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct FunctionsAir; impl BaseAir for FunctionsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for FunctionsAir { } } -impl AirScriptAir for FunctionsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for FunctionsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -49,6 +53,6 @@ impl AirScriptAir for FunctionsAir { impl Air for FunctionsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/functions/functions_simple_plonky3.rs b/air-script/tests/functions/functions_simple_plonky3.rs index 3bce53acb..51c279755 100644 --- a/air-script/tests/functions/functions_simple_plonky3.rs +++ b/air-script/tests/functions/functions_simple_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 9; - +pub const MAIN_WIDTH: usize = 9; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct FunctionsAir; impl BaseAir for FunctionsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for FunctionsAir { } } -impl AirScriptAir for FunctionsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for FunctionsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -55,6 +59,6 @@ impl AirScriptAir for FunctionsAir { impl Air for FunctionsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/functions/test_air_plonky3.rs b/air-script/tests/functions/test_air_plonky3.rs index 7692bc485..ddea4098d 100644 --- a/air-script/tests/functions/test_air_plonky3.rs +++ b/air-script/tests/functions/test_air_plonky3.rs @@ -13,20 +13,20 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - functions::functions_complex_plonky3::{FunctionsAir, NUM_COLUMNS}, + functions::functions_complex_plonky3::{FunctionsAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/helpers/plonky3_traits.rs b/air-script/tests/helpers/plonky3_traits.rs index 64537f7e4..d4a1f487d 100644 --- a/air-script/tests/helpers/plonky3_traits.rs +++ b/air-script/tests/helpers/plonky3_traits.rs @@ -9,21 +9,23 @@ use p3_matrix::{ }; /// Miden/AirScript-specific AIR. Replaces BaseAir for this forked target. -pub trait AirScriptAir { - /// Compile-time shape for this AIR. - const MAIN_WIDTH: usize; - const AUX_WIDTH: usize; // EF aux columns used by buses/perm args - const PERIOD: usize; // 0 == no periodic columns - const NUM_ALPHA_CHALLENGES: usize; // alpha_powers().len() +pub trait AirScriptAir> { + /// Auxiliary width of the AIR. + fn aux_width(&self) -> usize { + 0 + } + + /// Number of alpha challenges used in the AIR. + fn num_alpha_challenges(&self) -> usize { + 0 + } /// Periodic constants (base-field) backing periodic_evals(). - //fn periodic_table(&self) -> &'static [&'static [F]]; + // fn periodic_table(&self) -> &'static [&'static [F]]; fn periodic_table(&self) -> Vec>; /// Single entrypoint: encodes main + aux + boundary constraints. - fn eval(&self, builder: &mut AB) - where - AB: AirScriptBuilder; + fn eval(&self, builder: &mut AB); } /// Target trait for AirScript codegen. Implemented by the prover. @@ -257,7 +259,7 @@ pub(crate) fn check_constraints_with_airscript_traits( F: Field, EF: ExtensionField, A: for<'a> Air>, - A: AirScriptAir, + A: for<'a> AirScriptAir>, { let height = main.height(); @@ -274,7 +276,7 @@ pub(crate) fn check_constraints_with_airscript_traits( air.periodic_table().iter().map(|col| col[i % col.len()]).collect(); let periodic_columns: Vec = periodic_columns_base.iter().map(|&v| EF::from(v)).collect(); - let aux_bus_boundary_values: Vec<_> = (0..A::AUX_WIDTH).map(|_| EF::GENERATOR).collect(); + let aux_bus_boundary_values: Vec<_> = (0..air.aux_width()).map(|_| EF::GENERATOR).collect(); let alpha = EF::GENERATOR; // TODO let beta = EF::GENERATOR; // TODO @@ -288,7 +290,7 @@ pub(crate) fn check_constraints_with_airscript_traits( periodic_columns, alpha, beta, - alpha_powers: (0..A::NUM_ALPHA_CHALLENGES) + alpha_powers: (0..air.num_alpha_challenges()) .map(|power| alpha.exp_u64(power as u64)) .collect(), aux_bus_boundary_values, diff --git a/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs b/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs index 6a31ef663..d314f4927 100644 --- a/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs +++ b/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 4; - +pub const MAIN_WIDTH: usize = 4; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct TraceAccessAir; impl BaseAir for TraceAccessAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for TraceAccessAir { } } -impl AirScriptAir for TraceAccessAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for TraceAccessAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -48,6 +52,6 @@ impl AirScriptAir for TraceAccessAir { impl Air for TraceAccessAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/indexed_trace_access/test_air_plonky3.rs b/air-script/tests/indexed_trace_access/test_air_plonky3.rs index 4c40c296f..6cc8a63f3 100644 --- a/air-script/tests/indexed_trace_access/test_air_plonky3.rs +++ b/air-script/tests/indexed_trace_access/test_air_plonky3.rs @@ -15,18 +15,18 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, - indexed_trace_access::indexed_trace_access_plonky3::{NUM_COLUMNS, TraceAccessAir}, + indexed_trace_access::indexed_trace_access_plonky3::{MAIN_WIDTH, TraceAccessAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs b/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs index eba358ffc..4a693aa6f 100644 --- a/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs +++ b/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 2; - +pub const MAIN_WIDTH: usize = 2; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct ListComprehensionAir; impl BaseAir for ListComprehensionAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for ListComprehensionAir { } } -impl AirScriptAir for ListComprehensionAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for ListComprehensionAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -50,6 +54,6 @@ impl AirScriptAir for ListComprehensionAir { impl Air for ListComprehensionAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/list_comprehension/list_comprehension_plonky3.rs b/air-script/tests/list_comprehension/list_comprehension_plonky3.rs index b42758fb2..8b853068d 100644 --- a/air-script/tests/list_comprehension/list_comprehension_plonky3.rs +++ b/air-script/tests/list_comprehension/list_comprehension_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 16; - +pub const MAIN_WIDTH: usize = 16; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct ListComprehensionAir; impl BaseAir for ListComprehensionAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for ListComprehensionAir { } } -impl AirScriptAir for ListComprehensionAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for ListComprehensionAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -53,6 +57,6 @@ impl AirScriptAir for ListComprehensionAir { impl Air for ListComprehensionAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/list_comprehension/test_air_plonky3.rs b/air-script/tests/list_comprehension/test_air_plonky3.rs index b02c359eb..d0071c4dc 100644 --- a/air-script/tests/list_comprehension/test_air_plonky3.rs +++ b/air-script/tests/list_comprehension/test_air_plonky3.rs @@ -15,18 +15,18 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, - list_comprehension::list_comprehension_plonky3::{ListComprehensionAir, NUM_COLUMNS}, + list_comprehension::list_comprehension_plonky3::{ListComprehensionAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/list_folding/list_folding_plonky3.rs b/air-script/tests/list_folding/list_folding_plonky3.rs index 0e63eb920..eab864003 100644 --- a/air-script/tests/list_folding/list_folding_plonky3.rs +++ b/air-script/tests/list_folding/list_folding_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 17; - +pub const MAIN_WIDTH: usize = 17; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct ListFoldingAir; impl BaseAir for ListFoldingAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for ListFoldingAir { } } -impl AirScriptAir for ListFoldingAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for ListFoldingAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -51,6 +55,6 @@ impl AirScriptAir for ListFoldingAir { impl Air for ListFoldingAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/list_folding/test_air_plonky3.rs b/air-script/tests/list_folding/test_air_plonky3.rs index 6c6300eba..96b89194c 100644 --- a/air-script/tests/list_folding/test_air_plonky3.rs +++ b/air-script/tests/list_folding/test_air_plonky3.rs @@ -15,18 +15,18 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, - list_folding::list_folding_plonky3::{ListFoldingAir, NUM_COLUMNS}, + list_folding::list_folding_plonky3::{ListFoldingAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/periodic_columns/periodic_columns_plonky3.rs b/air-script/tests/periodic_columns/periodic_columns_plonky3.rs index a61edaf06..688221f5a 100644 --- a/air-script/tests/periodic_columns/periodic_columns_plonky3.rs +++ b/air-script/tests/periodic_columns/periodic_columns_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 3; - +pub const MAIN_WIDTH: usize = 3; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 2; +pub const PERIOD: usize = 8; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct PeriodicColumnsAir; impl BaseAir for PeriodicColumnsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,11 +24,15 @@ impl BaseAirWithPublicValues for PeriodicColumnsAir { } } -impl AirScriptAir for PeriodicColumnsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for PeriodicColumnsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { vec![ vec![F::from_u64(1), F::from_u64(0), F::from_u64(0), F::from_u64(0)], @@ -33,12 +40,10 @@ impl AirScriptAir for PeriodicColumnsAir { ] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -51,6 +56,6 @@ impl AirScriptAir for PeriodicColumnsAir { impl Air for PeriodicColumnsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/periodic_columns/test_air_plonky3.rs b/air-script/tests/periodic_columns/test_air_plonky3.rs index 2f5c74bfa..7342c8296 100644 --- a/air-script/tests/periodic_columns/test_air_plonky3.rs +++ b/air-script/tests/periodic_columns/test_air_plonky3.rs @@ -15,18 +15,18 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, - periodic_columns::periodic_columns_plonky3::{NUM_COLUMNS, PeriodicColumnsAir}, + periodic_columns::periodic_columns_plonky3::{MAIN_WIDTH, PeriodicColumnsAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/pub_inputs/pub_inputs_plonky3.rs b/air-script/tests/pub_inputs/pub_inputs_plonky3.rs index 2a70abe19..96b3bb6da 100644 --- a/air-script/tests/pub_inputs/pub_inputs_plonky3.rs +++ b/air-script/tests/pub_inputs/pub_inputs_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 4; - +pub const MAIN_WIDTH: usize = 4; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 32; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct PubInputsAir; impl BaseAir for PubInputsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for PubInputsAir { } } -impl AirScriptAir for PubInputsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for PubInputsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -55,6 +59,6 @@ impl AirScriptAir for PubInputsAir { impl Air for PubInputsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/pub_inputs/test_air_plonky3.rs b/air-script/tests/pub_inputs/test_air_plonky3.rs index 5b5ffbcef..87d39db5a 100644 --- a/air-script/tests/pub_inputs/test_air_plonky3.rs +++ b/air-script/tests/pub_inputs/test_air_plonky3.rs @@ -15,18 +15,18 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, - pub_inputs::pub_inputs_plonky3::{NUM_COLUMNS, PubInputsAir}, + pub_inputs::pub_inputs_plonky3::{MAIN_WIDTH, PubInputsAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/selectors/selectors_combine_complex_plonky3.rs b/air-script/tests/selectors/selectors_combine_complex_plonky3.rs index f6e1a97f2..aebac82ba 100644 --- a/air-script/tests/selectors/selectors_combine_complex_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_complex_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 6; - +pub const MAIN_WIDTH: usize = 6; +pub const AUX_WIDTH: usize = 1; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; +pub const NUM_ALPHA_CHALLENGES: usize = 3; pub struct SelectorsAir; impl BaseAir for SelectorsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for SelectorsAir { } } -impl AirScriptAir for SelectorsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 3; +impl> AirScriptAir for SelectorsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -50,6 +54,6 @@ impl AirScriptAir for SelectorsAir { impl Air for SelectorsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_combine_simple_plonky3.rs b/air-script/tests/selectors/selectors_combine_simple_plonky3.rs index 8732ca151..022d2e452 100644 --- a/air-script/tests/selectors/selectors_combine_simple_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_simple_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 4; - +pub const MAIN_WIDTH: usize = 4; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct SelectorsAir; impl BaseAir for SelectorsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for SelectorsAir { } } -impl AirScriptAir for SelectorsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for SelectorsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -49,6 +53,6 @@ impl AirScriptAir for SelectorsAir { impl Air for SelectorsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs b/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs index 0721984ca..252b99427 100644 --- a/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 6; - +pub const MAIN_WIDTH: usize = 6; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct SelectorsAir; impl BaseAir for SelectorsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for SelectorsAir { } } -impl AirScriptAir for SelectorsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for SelectorsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -50,6 +54,6 @@ impl AirScriptAir for SelectorsAir { impl Air for SelectorsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_plonky3.rs b/air-script/tests/selectors/selectors_plonky3.rs index c6c27edfe..ce51e091e 100644 --- a/air-script/tests/selectors/selectors_plonky3.rs +++ b/air-script/tests/selectors/selectors_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 4; - +pub const MAIN_WIDTH: usize = 4; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct SelectorsAir; impl BaseAir for SelectorsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for SelectorsAir { } } -impl AirScriptAir for SelectorsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for SelectorsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -49,6 +53,6 @@ impl AirScriptAir for SelectorsAir { impl Air for SelectorsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs b/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs index d9cb2bb25..bce55dfbd 100644 --- a/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs +++ b/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 4; - +pub const MAIN_WIDTH: usize = 4; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct SelectorsAir; impl BaseAir for SelectorsAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for SelectorsAir { } } -impl AirScriptAir for SelectorsAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for SelectorsAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -49,6 +53,6 @@ impl AirScriptAir for SelectorsAir { impl Air for SelectorsAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/selectors/test_air_plonky3.rs b/air-script/tests/selectors/test_air_plonky3.rs index 151323197..4a05ee0c9 100644 --- a/air-script/tests/selectors/test_air_plonky3.rs +++ b/air-script/tests/selectors/test_air_plonky3.rs @@ -15,18 +15,18 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, - selectors::selectors_with_evaluators_plonky3::{NUM_COLUMNS, SelectorsAir}, + selectors::selectors_with_evaluators_plonky3::{MAIN_WIDTH, SelectorsAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/system/system_plonky3.rs b/air-script/tests/system/system_plonky3.rs index f1c1f2805..1ec96a91c 100644 --- a/air-script/tests/system/system_plonky3.rs +++ b/air-script/tests/system/system_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 3; - +pub const MAIN_WIDTH: usize = 3; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct SystemAir; impl BaseAir for SystemAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for SystemAir { } } -impl AirScriptAir for SystemAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for SystemAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -48,6 +52,6 @@ impl AirScriptAir for SystemAir { impl Air for SystemAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/system/test_air_plonky3.rs b/air-script/tests/system/test_air_plonky3.rs index 5bf16d4e8..45e6ca693 100644 --- a/air-script/tests/system/test_air_plonky3.rs +++ b/air-script/tests/system/test_air_plonky3.rs @@ -15,18 +15,18 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, - system::system_plonky3::{NUM_COLUMNS, SystemAir}, + system::system_plonky3::{MAIN_WIDTH, SystemAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/trace_col_groups/test_air_plonky3.rs b/air-script/tests/trace_col_groups/test_air_plonky3.rs index 56e5cdd7c..de115e6e3 100644 --- a/air-script/tests/trace_col_groups/test_air_plonky3.rs +++ b/air-script/tests/trace_col_groups/test_air_plonky3.rs @@ -15,18 +15,18 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, - trace_col_groups::trace_col_groups_plonky3::{NUM_COLUMNS, TraceColGroupAir}, + trace_col_groups::trace_col_groups_plonky3::{MAIN_WIDTH, TraceColGroupAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs b/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs index 78ee3f372..ee2ddb74d 100644 --- a/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs +++ b/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 9; - +pub const MAIN_WIDTH: usize = 9; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct TraceColGroupAir; impl BaseAir for TraceColGroupAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,22 +24,23 @@ impl BaseAirWithPublicValues for TraceColGroupAir { } } -impl AirScriptAir for TraceColGroupAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for TraceColGroupAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { - vec![ - ] + vec![] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -49,6 +53,6 @@ impl AirScriptAir for TraceColGroupAir { impl Air for TraceColGroupAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/air-script/tests/variables/test_air_plonky3.rs b/air-script/tests/variables/test_air_plonky3.rs index db94f1c30..a008fe31e 100644 --- a/air-script/tests/variables/test_air_plonky3.rs +++ b/air-script/tests/variables/test_air_plonky3.rs @@ -15,18 +15,18 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, helpers::check_constraints_with_airscript_traits, - variables::variables_plonky3::{NUM_COLUMNS, VariablesAir}, + variables::variables_plonky3::{MAIN_WIDTH, VariablesAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { let num_rows = 32; - let trace_length = num_rows * NUM_COLUMNS; + let trace_length = num_rows * MAIN_WIDTH; let mut long_trace = F::zero_vec(trace_length); - let mut trace = RowMajorMatrix::new(long_trace, NUM_COLUMNS); + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); - let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; NUM_COLUMNS]>() }; + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; assert!(prefix.is_empty(), "Alignment should match"); assert!(suffix.is_empty(), "Alignment should match"); assert_eq!(rows.len(), num_rows); diff --git a/air-script/tests/variables/variables_plonky3.rs b/air-script/tests/variables/variables_plonky3.rs index d9efbf68c..66831b1c3 100644 --- a/air-script/tests/variables/variables_plonky3.rs +++ b/air-script/tests/variables/variables_plonky3.rs @@ -3,15 +3,18 @@ use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const NUM_COLUMNS: usize = 4; - +pub const MAIN_WIDTH: usize = 4; +pub const AUX_WIDTH: usize = 0; +pub const NUM_PERIODIC_VALUES: usize = 1; +pub const PERIOD: usize = 8; pub const NUM_PUBLIC_VALUES: usize = 32; +pub const NUM_ALPHA_CHALLENGES: usize = 0; pub struct VariablesAir; impl BaseAir for VariablesAir { fn width(&self) -> usize { - NUM_COLUMNS + MAIN_WIDTH } } @@ -21,23 +24,25 @@ impl BaseAirWithPublicValues for VariablesAir { } } -impl AirScriptAir for VariablesAir { - const MAIN_WIDTH: usize = NUM_COLUMNS; - const AUX_WIDTH: usize = 0; - const PERIOD: usize = 0; - const NUM_ALPHA_CHALLENGES: usize = 0; +impl> AirScriptAir for VariablesAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + fn periodic_table(&self) -> Vec> { vec![ vec![F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(1), F::from_u64(0)], ] } - fn eval(&self, builder: &mut AB) - where AB: AirScriptBuilder, - { + fn eval(&self, builder: &mut AB) { let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values = builder.periodic_evals().to_vec(); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), @@ -53,6 +58,6 @@ impl AirScriptAir for VariablesAir { impl Air for VariablesAir { fn eval(&self, builder: &mut AB) { - >::eval(self, builder); + >::eval(self, builder); } } \ No newline at end of file diff --git a/codegen/plonky3/src/air/mod.rs b/codegen/plonky3/src/air/mod.rs index 608b25f15..4a54ec23b 100644 --- a/codegen/plonky3/src/air/mod.rs +++ b/codegen/plonky3/src/air/mod.rs @@ -19,8 +19,11 @@ use crate::air::{ pub(super) fn add_air(scope: &mut Scope, ir: &Air) { let name = ir.name(); + // add the constants needed (outside any traits for object safety). + add_constants(scope, ir); + // add the Air struct and its base implementation. - add_air_struct(scope, ir, name); + add_air_struct(scope, name); // add AirScriptAir trait implementation for the provided AirIR. add_air_script_trait(scope, ir, name); @@ -29,20 +32,37 @@ pub(super) fn add_air(scope: &mut Scope, ir: &Air) { add_air_trait(scope, name); } -/// Updates the provided scope with a custom Air struct. -fn add_air_struct(scope: &mut Scope, ir: &Air, name: &str) { - scope.raw(format!("pub const NUM_COLUMNS: usize = {};", ir.trace_segment_widths[0])); - +/// Updates the provided scope with constants needed for the custom Air struct and trait +/// implementations. +fn add_constants(scope: &mut Scope, ir: &Air) { + let main_width = ir.trace_segment_widths[0]; + let aux_width = ir.trace_segment_widths.get(1).cloned().unwrap_or(0); + let num_periodic_values = ir.periodic_columns().count(); + let period = ir.periodic_columns().map(|col| col.period()).max().unwrap_or(0); let num_public_values = ir.public_inputs().map(|public_input| public_input.size()).sum::(); - scope.raw(format!("pub const NUM_PUBLIC_VALUES: usize = {num_public_values};")); + let num_alpha_challenges = ir.num_random_values; + let constants = [ + format!("pub const MAIN_WIDTH: usize = {main_width};"), + format!("pub const AUX_WIDTH: usize = {aux_width};"), + format!("pub const NUM_PERIODIC_VALUES: usize = {num_periodic_values};"), + format!("pub const PERIOD: usize = {period};"), + format!("pub const NUM_PUBLIC_VALUES: usize = {num_public_values};"), + format!("pub const NUM_ALPHA_CHALLENGES: usize = {num_alpha_challenges};"), + ]; + + scope.raw(constants.join("\n")); +} + +/// Updates the provided scope with a custom Air struct. +fn add_air_struct(scope: &mut Scope, name: &str) { // define the custom Air struct. scope.new_struct(name).vis("pub"); // add the custom BaseAir implementation block let base_air_impl = scope.new_impl(name).generic("F").impl_trait("BaseAir"); - base_air_impl.new_fn("width").arg_ref_self().ret("usize").line("NUM_COLUMNS"); + base_air_impl.new_fn("width").arg_ref_self().ret("usize").line("MAIN_WIDTH"); // add the custom BaseAirWithPublicValues implementation block let base_air_with_public_values_impl = @@ -56,50 +76,63 @@ fn add_air_struct(scope: &mut Scope, ir: &Air, name: &str) { fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { // add the custom AirScriptAir implementation block - let air_script_impl = scope.new_impl(name).generic("F: Field").impl_trait("AirScriptAir"); - air_script_impl.associate_const("MAIN_WIDTH", "usize", "NUM_COLUMNS", ""); - air_script_impl.associate_const("AUX_WIDTH", "usize", "0", ""); - air_script_impl.associate_const("PERIOD", "usize", "0", ""); - let num_alpha_challenges = ir.num_random_values; - air_script_impl.associate_const( - "NUM_ALPHA_CHALLENGES", - "usize", - format!("{num_alpha_challenges}"), - "", - ); + let air_script_impl = scope + .new_impl(name) + .generic("F: Field") + .generic("AB: AirScriptBuilder") + .impl_trait("AirScriptAir"); + + // add the aux_width function + air_script_impl + .new_fn("aux_width") + .arg_ref_self() + .ret("usize") + .line("AUX_WIDTH"); + // add the num_alpha_challenges function + air_script_impl + .new_fn("num_alpha_challenges") + .arg_ref_self() + .ret("usize") + .line("NUM_ALPHA_CHALLENGES"); + + // add the periodic_table function let periodic_table_func = air_script_impl .new_fn("periodic_table") .arg_ref_self() - //.ret("&'static [&'static [Self::F]]"); + //.ret("&'static [&'static [F]]"); .ret("Vec>"); - periodic_table_func.line("vec!["); - for col in ir.periodic_columns() { - let values_str = col.values - .iter() - .map(|v| format!("F::from_u64({v})")) // or use a custom formatter if needed - .collect::>() - .join(", "); - periodic_table_func.line(format!(" vec![{values_str}],")); + if ir.periodic_columns().count() == 0 { + periodic_table_func.line("vec![]"); + } else { + periodic_table_func.line("vec!["); + for col in ir.periodic_columns() { + let values_str = col.values + .iter() + .map(|v| format!("F::from_u64({v})")) // or use a custom formatter if needed + .collect::>() + .join(", "); + periodic_table_func.line(format!(" vec![{values_str}],")); + } + periodic_table_func.line("]"); } - periodic_table_func.line("]"); - let eval_func = air_script_impl - .new_fn("eval") - .generic("AB") - .arg_ref_self() - .arg("builder", "&mut AB") - .bound("AB", "AirScriptBuilder"); + // add the eval function + let eval_func = air_script_impl.new_fn("eval").arg_ref_self().arg("builder", "&mut AB"); eval_func.line("let main = builder.main();"); eval_func.line("let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect(\"Wrong number of public values\");"); - eval_func.line("let periodic_values = builder.periodic_evals().to_vec();"); + eval_func.line("let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect(\"Wrong number of periodic values\");"); eval_func.line("let (main_current, main_next) = ("); eval_func.line(" main.row_slice(0).unwrap(),"); eval_func.line(" main.row_slice(1).unwrap(),"); eval_func.line(");"); + eval_func.line(""); + eval_func.line("// Main boundary constraints"); add_main_boundary_constraints(eval_func, ir); + eval_func.line(""); + eval_func.line("// Main integrity/transition constraints"); add_main_integrity_constraints(eval_func, ir); } @@ -110,5 +143,5 @@ fn add_air_trait(scope: &mut Scope, name: &str) { let air_impl = scope.new_impl(name).generic("AB: AirScriptBuilder").impl_trait("Air"); let eval_func = air_impl.new_fn("eval").arg_ref_self().arg("builder", "&mut AB"); - eval_func.line(">::eval(self, builder);"); + eval_func.line(">::eval(self, builder);"); } From cbea42de9f9de42db6c617993b6856b2f339e35d Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 6 Nov 2025 14:38:58 +0100 Subject: [PATCH 05/22] feat: handle aux trace --- CHANGELOG.md | 1 + air-script/tests/binary/binary_plonky3.rs | 14 +- air-script/tests/bitwise/bitwise_plonky3.rs | 44 ++--- air-script/tests/buses/buses_complex.air | 8 +- .../tests/buses/buses_complex_plonky3.rs | 36 +++- .../tests/buses/buses_simple_plonky3.rs | 23 ++- .../buses_varlen_boundary_both_plonky3.rs | 23 ++- .../buses_varlen_boundary_first_plonky3.rs | 24 ++- .../buses_varlen_boundary_last_plonky3.rs | 24 ++- air-script/tests/buses/test_air_plonky3.rs | 19 ++- .../computed_indices_complex_plonky3.rs | 12 +- .../computed_indices_simple_plonky3.rs | 26 +-- .../constant_in_range_plonky3.rs | 12 +- .../tests/constants/constants_plonky3.rs | 30 ++-- .../constraint_comprehension_plonky3.rs | 18 +- .../tests/evaluators/evaluators_plonky3.rs | 30 ++-- .../tests/fibonacci/fibonacci_plonky3.rs | 18 +- .../functions/functions_complex_plonky3.rs | 14 +- .../functions/functions_simple_plonky3.rs | 26 +-- air-script/tests/helpers/plonky3_traits.rs | 141 ++++++++++++++-- .../indexed_trace_access_plonky3.rs | 12 +- .../list_comprehension_nested_plonky3.rs | 16 +- .../list_comprehension_plonky3.rs | 22 ++- .../list_folding/list_folding_plonky3.rs | 18 +- .../periodic_columns_plonky3.rs | 14 +- .../tests/pub_inputs/pub_inputs_plonky3.rs | 26 +-- .../selectors_combine_complex_plonky3.rs | 33 +++- .../selectors_combine_simple_plonky3.rs | 14 +- ...ombine_with_list_comprehensions_plonky3.rs | 16 +- .../tests/selectors/selectors_plonky3.rs | 14 +- .../selectors_with_evaluators_plonky3.rs | 14 +- air-script/tests/system/system_plonky3.rs | 12 +- .../trace_col_groups_plonky3.rs | 14 +- .../tests/variables/variables_plonky3.rs | 20 ++- air/src/passes/expand_buses.rs | 14 +- .../plonky3/src/air/boundary_constraints.rs | 55 +++++-- codegen/plonky3/src/air/graph.rs | 154 +++++++++++++----- .../plonky3/src/air/integrity_constraints.rs | 34 ++-- codegen/plonky3/src/air/mod.rs | 35 +++- codegen/plonky3/src/imports.rs | 1 + 40 files changed, 778 insertions(+), 303 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f5350d29..59d55ecc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Fix regressions on MIR and list_comprehensions (#449). - Add Plonky3 codegen backend (#461). - Fixed a vector unrolling issue in nested match evaluations (#491). +- In Plonky3 codegen, use AirScriptAir and AirScriptBuilder traits, and generate aux constraints (#508). ## 0.4.0 (2025-06-20) diff --git a/air-script/tests/binary/binary_plonky3.rs b/air-script/tests/binary/binary_plonky3.rs index 956f773a8..2dad894a8 100644 --- a/air-script/tests/binary/binary_plonky3.rs +++ b/air-script/tests/binary/binary_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,16 +38,20 @@ impl> AirScriptAir for BinaryAir { } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into() - public_values[0].into()); - builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); - builder.assert_zero_ext::<_>(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into() - public_values[0].into()); + + // Main integrity/transition constraints + builder.assert_zero(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.assert_zero(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); } } diff --git a/air-script/tests/bitwise/bitwise_plonky3.rs b/air-script/tests/bitwise/bitwise_plonky3.rs index 332dbb70f..86b847eec 100644 --- a/air-script/tests/bitwise/bitwise_plonky3.rs +++ b/air-script/tests/bitwise/bitwise_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -41,31 +41,35 @@ impl> AirScriptAir for BitwiseAir { } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[13].clone().into()); - builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); - builder.when_transition().assert_zero_ext::<_>(periodic_values[1].into() * (main_next[0].clone().into() - main_current[0].clone().into())); - builder.assert_zero_ext::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); - builder.assert_zero_ext::<_>(main_current[4].clone().into() * main_current[4].clone().into() - main_current[4].clone().into()); - builder.assert_zero_ext::<_>(main_current[5].clone().into() * main_current[5].clone().into() - main_current[5].clone().into()); - builder.assert_zero_ext::<_>(main_current[6].clone().into() * main_current[6].clone().into() - main_current[6].clone().into()); - builder.assert_zero_ext::<_>(main_current[7].clone().into() * main_current[7].clone().into() - main_current[7].clone().into()); - builder.assert_zero_ext::<_>(main_current[8].clone().into() * main_current[8].clone().into() - main_current[8].clone().into()); - builder.assert_zero_ext::<_>(main_current[9].clone().into() * main_current[9].clone().into() - main_current[9].clone().into()); - builder.assert_zero_ext::<_>(main_current[10].clone().into() * main_current[10].clone().into() - main_current[10].clone().into()); - builder.assert_zero_ext::<_>(periodic_values[0].into() * (main_current[1].clone().into() - (main_current[3].clone().into() + main_current[4].clone().into().double() + AB::Expr::from_u64(4) * main_current[5].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into()))); - builder.assert_zero_ext::<_>(periodic_values[0].into() * (main_current[2].clone().into() - (main_current[7].clone().into() + main_current[8].clone().into().double() + AB::Expr::from_u64(4) * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[10].clone().into()))); - builder.when_transition().assert_zero_ext::<_>(periodic_values[1].into() * (main_next[1].clone().into() - (main_current[1].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[4].clone().into().double() + AB::Expr::from_u64(4) * main_current[5].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into()))); - builder.when_transition().assert_zero_ext::<_>(periodic_values[1].into() * (main_next[2].clone().into() - (main_current[2].clone().into() * AB::Expr::from_u64(16) + main_current[7].clone().into() + main_current[8].clone().into().double() + AB::Expr::from_u64(4) * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[10].clone().into()))); - builder.assert_zero_ext::<_>(periodic_values[0].into() * main_current[11].clone().into()); - builder.when_transition().assert_zero_ext::<_>(periodic_values[1].into() * (main_current[12].clone().into() - main_next[11].clone().into())); - builder.assert_zero_ext::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() * main_current[7].clone().into() + main_current[4].clone().into().double() * main_current[8].clone().into() + AB::Expr::from_u64(4) * main_current[5].clone().into() * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into() * main_current[10].clone().into())) + main_current[0].clone().into() * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[7].clone().into() - main_current[3].clone().into().double() * main_current[7].clone().into() + (main_current[4].clone().into() + main_current[8].clone().into() - main_current[4].clone().into().double() * main_current[8].clone().into()).double() + AB::Expr::from_u64(4) * (main_current[5].clone().into() + main_current[9].clone().into() - main_current[5].clone().into().double() * main_current[9].clone().into()) + AB::Expr::from_u64(8) * (main_current[6].clone().into() + main_current[10].clone().into() - main_current[6].clone().into().double() * main_current[10].clone().into())))); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[13].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); + builder.assert_zero(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); + builder.assert_zero(main_current[4].clone().into() * main_current[4].clone().into() - main_current[4].clone().into()); + builder.assert_zero(main_current[5].clone().into() * main_current[5].clone().into() - main_current[5].clone().into()); + builder.assert_zero(main_current[6].clone().into() * main_current[6].clone().into() - main_current[6].clone().into()); + builder.assert_zero(main_current[7].clone().into() * main_current[7].clone().into() - main_current[7].clone().into()); + builder.assert_zero(main_current[8].clone().into() * main_current[8].clone().into() - main_current[8].clone().into()); + builder.assert_zero(main_current[9].clone().into() * main_current[9].clone().into() - main_current[9].clone().into()); + builder.assert_zero(main_current[10].clone().into() * main_current[10].clone().into() - main_current[10].clone().into()); + builder.assert_zero_ext(periodic_values[0].into() * (AB::ExprEF::from(main_current[1].clone().into()) - (AB::ExprEF::from(main_current[3].clone().into()) + AB::ExprEF::from(main_current[4].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[6].clone().into())))); + builder.assert_zero_ext(periodic_values[0].into() * (AB::ExprEF::from(main_current[2].clone().into()) - (AB::ExprEF::from(main_current[7].clone().into()) + AB::ExprEF::from(main_current[8].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[9].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[10].clone().into())))); + builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_next[1].clone().into()) - (AB::ExprEF::from(main_current[1].clone().into()) * AB::ExprEF::from_u64(16) + AB::ExprEF::from(main_current[3].clone().into()) + AB::ExprEF::from(main_current[4].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[6].clone().into())))); + builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_next[2].clone().into()) - (AB::ExprEF::from(main_current[2].clone().into()) * AB::ExprEF::from_u64(16) + AB::ExprEF::from(main_current[7].clone().into()) + AB::ExprEF::from(main_current[8].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[9].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[10].clone().into())))); + builder.assert_zero_ext(periodic_values[0].into() * AB::ExprEF::from(main_current[11].clone().into())); + builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_current[12].clone().into()) - AB::ExprEF::from(main_next[11].clone().into()))); + builder.assert_zero((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() * main_current[7].clone().into() + main_current[4].clone().into().double() * main_current[8].clone().into() + AB::Expr::from_u64(4) * main_current[5].clone().into() * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into() * main_current[10].clone().into())) + main_current[0].clone().into() * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[7].clone().into() - main_current[3].clone().into().double() * main_current[7].clone().into() + (main_current[4].clone().into() + main_current[8].clone().into() - main_current[4].clone().into().double() * main_current[8].clone().into()).double() + AB::Expr::from_u64(4) * (main_current[5].clone().into() + main_current[9].clone().into() - main_current[5].clone().into().double() * main_current[9].clone().into()) + AB::Expr::from_u64(8) * (main_current[6].clone().into() + main_current[10].clone().into() - main_current[6].clone().into().double() * main_current[10].clone().into())))); } } diff --git a/air-script/tests/buses/buses_complex.air b/air-script/tests/buses/buses_complex.air index 401ca8b67..f27a2745c 100644 --- a/air-script/tests/buses/buses_complex.air +++ b/air-script/tests/buses/buses_complex.air @@ -1,7 +1,7 @@ def BusesAir trace_columns { - main: [a, b, s1, s2, d], + main: [a, b, s1, s2, s3, s4, d], } buses { @@ -34,7 +34,7 @@ integrity_constraints { p.insert(2, b) when 1 - s1; p.remove(2, a) when 1 - s2; - q.insert(3, a) when s1; - q.insert(3, a) when s1; - q.remove(4, b) with d; + q.insert(3, a) when s3; + q.insert(3, a) when s4; + q.remove(3, b) with d; } diff --git a/air-script/tests/buses/buses_complex_plonky3.rs b/air-script/tests/buses/buses_complex_plonky3.rs index 43978f9df..4b062f2af 100644 --- a/air-script/tests/buses/buses_complex_plonky3.rs +++ b/air-script/tests/buses/buses_complex_plonky3.rs @@ -1,14 +1,14 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; -pub const MAIN_WIDTH: usize = 5; +pub const MAIN_WIDTH: usize = 7; pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_ALPHA_CHALLENGES: usize = 4; +pub const NUM_ALPHA_CHALLENGES: usize = 3; pub struct BusesAir; @@ -38,16 +38,38 @@ impl> AirScriptAir for BusesAir { } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); - builder.assert_zero_ext::<_>(main_current[2].clone().into() * main_current[2].clone().into() - main_current[2].clone().into()); - builder.assert_zero_ext::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); + let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); + let beta = builder.beta(); + let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); + let aux = builder.permutation(); + let (aux_current, aux_next) = ( + aux.row_slice(0).unwrap(), + aux.row_slice(1).unwrap(), + ); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero(main_current[2].clone().into() * main_current[2].clone().into() - main_current[2].clone().into()); + builder.assert_zero(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); + + // Aux boundary constraints + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + + // Aux integrity/transition constraints + builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into() + (AB::ExprEF::from_u64(3) + AB::ExprEF::from(main_current[1].clone().into())) * alpha_challenges[1].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[2].into()) * AB::ExprEF::from(main_current[2].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[2].clone().into())) * ((beta.into() + alpha_challenges[0].into().double() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[1].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[2].clone().into())) + AB::ExprEF::from(main_current[2].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + (AB::ExprEF::from_u64(3) + AB::ExprEF::from(main_current[1].clone().into())) * alpha_challenges[1].into() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[2].into()) * AB::ExprEF::from(main_current[3].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[3].clone().into())) * ((beta.into() + alpha_challenges[0].into().double() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[3].clone().into())) + AB::ExprEF::from(main_current[3].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[1].into()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[1].into()) * AB::ExprEF::from(main_current[4].clone().into()) + (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[1].into()) * AB::ExprEF::from(main_current[5].clone().into()) - ((beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[1].into()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * AB::ExprEF::from(main_current[6].clone().into()))); } } diff --git a/air-script/tests/buses/buses_simple_plonky3.rs b/air-script/tests/buses/buses_simple_plonky3.rs index c06f26e2b..7860bef38 100644 --- a/air-script/tests/buses/buses_simple_plonky3.rs +++ b/air-script/tests/buses/buses_simple_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_ALPHA_CHALLENGES: usize = 3; +pub const NUM_ALPHA_CHALLENGES: usize = 2; pub struct BusesAir; @@ -38,13 +38,30 @@ impl> AirScriptAir for BusesAir { } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); + let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); + let beta = builder.beta(); + let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); + let aux = builder.permutation(); + let (aux_current, aux_next) = ( + aux.row_slice(0).unwrap(), + aux.row_slice(1).unwrap(), + ); + + // Aux boundary constraints + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + + // Aux integrity/transition constraints + builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) + AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()).double())); } } diff --git a/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs b/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs index 9af5f0402..c44e77ac5 100644 --- a/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs +++ b/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 6; -pub const NUM_ALPHA_CHALLENGES: usize = 3; +pub const NUM_ALPHA_CHALLENGES: usize = 2; pub struct BusesAir; @@ -38,13 +38,30 @@ impl> AirScriptAir for BusesAir { } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); + let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); + let beta = builder.beta(); + let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); + let aux = builder.permutation(); + let (aux_current, aux_next) = ( + aux.row_slice(0).unwrap(), + aux.row_slice(1).unwrap(), + ); + + // Aux boundary constraints + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - aux_bus_boundary_values[0].into()); + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into()) - aux_bus_boundary_values[1].into()); + + // Aux integrity/transition constraints + builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into()) * (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE) + AB::ExprEF::ONE - (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE)) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()).double())); } } diff --git a/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs b/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs index c06f26e2b..a236a1336 100644 --- a/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs +++ b/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_ALPHA_CHALLENGES: usize = 3; +pub const NUM_ALPHA_CHALLENGES: usize = 2; pub struct BusesAir; @@ -38,13 +38,31 @@ impl> AirScriptAir for BusesAir { } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); + let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); + let beta = builder.beta(); + let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); + let aux = builder.permutation(); + let (aux_current, aux_next) = ( + aux.row_slice(0).unwrap(), + aux.row_slice(1).unwrap(), + ); + + // Aux boundary constraints + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - aux_bus_boundary_values[0].into()); + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into()) - aux_bus_boundary_values[1].into()); + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + + // Aux integrity/transition constraints + builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into()) * (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE) + AB::ExprEF::ONE - (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE)) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()).double())); } } diff --git a/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs b/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs index c06f26e2b..5099d3f0b 100644 --- a/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs +++ b/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_ALPHA_CHALLENGES: usize = 3; +pub const NUM_ALPHA_CHALLENGES: usize = 2; pub struct BusesAir; @@ -38,13 +38,31 @@ impl> AirScriptAir for BusesAir { } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); + let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); + let beta = builder.beta(); + let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); + let aux = builder.permutation(); + let (aux_current, aux_next) = ( + aux.row_slice(0).unwrap(), + aux.row_slice(1).unwrap(), + ); + + // Aux boundary constraints + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - aux_bus_boundary_values[0].into()); + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into()) - aux_bus_boundary_values[1].into()); + + // Aux integrity/transition constraints + builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into()) * (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE) + AB::ExprEF::ONE - (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE)) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()).double())); } } diff --git a/air-script/tests/buses/test_air_plonky3.rs b/air-script/tests/buses/test_air_plonky3.rs index fd443caf9..3f5af2f25 100644 --- a/air-script/tests/buses/test_air_plonky3.rs +++ b/air-script/tests/buses/test_air_plonky3.rs @@ -34,15 +34,30 @@ pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix< // Initialize first row rows[0][0] = F::ZERO; rows[0][1] = F::ZERO; + rows[0][2] = F::ZERO; + rows[0][3] = F::ZERO; + rows[0][4] = F::ZERO; + rows[0][5] = F::ZERO; + rows[0][6] = F::ZERO; // Fill subsequent rows using direct access to the rows array for i in 1..num_rows { let a_prev = rows[i - 1][0]; let b_prev = rows[i - 1][1]; + let c_prev = rows[i - 1][2]; + let d_prev = rows[i - 1][3]; + let e_prev = rows[i - 1][4]; + let f_prev = rows[i - 1][5]; + let g_prev = rows[i - 1][6]; // Update current row based on previous values - rows[i][0] = F::ONE - a_prev; - rows[i][1] = F::ONE - b_prev; + rows[i][0] = F::ZERO; + rows[i][1] = F::ZERO; + rows[i][2] = if i > 3 && i < 8 { F::ONE } else { F::ZERO }; // s1 is true 4 times + rows[i][3] = if i > 5 && i < 10 { F::ONE } else { F::ZERO }; // s2 is true 4 times + rows[i][4] = if i > 4 && i < 10 { F::ONE } else { F::ZERO }; // s3 is true 5 times + rows[i][5] = if i > 5 && i < 13 { F::ONE } else { F::ZERO }; // s4 is true 7 times + rows[i][6] = if i > 15 && i < 20 { F::from_u64(3) } else { F::ZERO }; // d is set to 3 four times } trace diff --git a/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs b/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs index 84f5cf63c..f39db8e83 100644 --- a/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs +++ b/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,15 +38,19 @@ impl> AirScriptAir for ComputedIndi } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); - builder.assert_zero_ext::<_>(main_current[2].clone().into() * AB::Expr::from_u64(3) + main_current[3].clone().into() * AB::Expr::from_u64(4)); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero(main_current[2].clone().into() * AB::Expr::from_u64(3) + main_current[3].clone().into() * AB::Expr::from_u64(4)); } } diff --git a/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs b/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs index 39c53d19c..4801d1b57 100644 --- a/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs +++ b/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,22 +38,26 @@ impl> AirScriptAir for ComputedIndi } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); - builder.assert_zero_ext::<_>(main_current[0].clone().into()); - builder.assert_zero_ext::<_>(main_current[1].clone().into() - AB::Expr::from_u64(2)); - builder.assert_zero_ext::<_>(main_current[2].clone().into() - AB::Expr::from_u64(4)); - builder.assert_zero_ext::<_>(main_current[3].clone().into() - AB::Expr::from_u64(6)); - builder.when_transition().assert_zero_ext::<_>(main_next[4].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[5].clone().into() - main_current[5].clone().into().double()); - builder.when_transition().assert_zero_ext::<_>(main_next[6].clone().into() - AB::Expr::from_u64(6) * main_current[6].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[7].clone().into() - AB::Expr::from_u64(12) * main_current[7].clone().into()); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero(main_current[0].clone().into()); + builder.assert_zero(main_current[1].clone().into() - AB::Expr::from_u64(2)); + builder.assert_zero(main_current[2].clone().into() - AB::Expr::from_u64(4)); + builder.assert_zero(main_current[3].clone().into() - AB::Expr::from_u64(6)); + builder.when_transition().assert_zero(main_next[4].clone().into()); + builder.when_transition().assert_zero(main_next[5].clone().into() - main_current[5].clone().into().double()); + builder.when_transition().assert_zero(main_next[6].clone().into() - AB::Expr::from_u64(6) * main_current[6].clone().into()); + builder.when_transition().assert_zero(main_next[7].clone().into() - AB::Expr::from_u64(12) * main_current[7].clone().into()); } } diff --git a/air-script/tests/constant_in_range/constant_in_range_plonky3.rs b/air-script/tests/constant_in_range/constant_in_range_plonky3.rs index 8b42c19c2..d946455fd 100644 --- a/air-script/tests/constant_in_range/constant_in_range_plonky3.rs +++ b/air-script/tests/constant_in_range/constant_in_range_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,15 +38,19 @@ impl> AirScriptAir for ConstantInRa } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[6].clone().into()); - builder.assert_zero_ext::<_>(main_current[0].clone().into() - (main_current[1].clone().into() - main_current[4].clone().into() - main_current[8].clone().into() + AB::Expr::ONE + main_current[2].clone().into() - main_current[5].clone().into() - main_current[9].clone().into() + AB::Expr::from_u64(2) + main_current[3].clone().into() - main_current[6].clone().into() - main_current[10].clone().into())); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[6].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero(main_current[0].clone().into() - (main_current[1].clone().into() - main_current[4].clone().into() - main_current[8].clone().into() + AB::Expr::ONE + main_current[2].clone().into() - main_current[5].clone().into() - main_current[9].clone().into() + AB::Expr::from_u64(2) + main_current[3].clone().into() - main_current[6].clone().into() - main_current[10].clone().into())); } } diff --git a/air-script/tests/constants/constants_plonky3.rs b/air-script/tests/constants/constants_plonky3.rs index 5828b7d4a..1864d37c6 100644 --- a/air-script/tests/constants/constants_plonky3.rs +++ b/air-script/tests/constants/constants_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,24 +38,28 @@ impl> AirScriptAir for ConstantsAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into() - AB::Expr::ONE); - builder.when_first_row().assert_zero_ext::<_>(main_current[1].clone().into() - AB::Expr::ONE); - builder.when_first_row().assert_zero_ext::<_>(main_current[2].clone().into()); - builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into() - AB::Expr::ONE); - builder.when_first_row().assert_zero_ext::<_>(main_current[4].clone().into() - AB::Expr::ONE); - builder.when_last_row().assert_zero_ext::<_>(main_current[6].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); - builder.when_transition().assert_zero_ext::<_>(main_next[1].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[2].clone().into() - main_current[2].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[5].clone().into() - (main_current[5].clone().into() + AB::Expr::ONE)); - builder.assert_zero_ext::<_>(main_current[4].clone().into() - AB::Expr::ONE); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into() - AB::Expr::ONE); + builder.when_first_row().assert_zero(main_current[1].clone().into() - AB::Expr::ONE); + builder.when_first_row().assert_zero(main_current[2].clone().into()); + builder.when_first_row().assert_zero(main_current[3].clone().into() - AB::Expr::ONE); + builder.when_first_row().assert_zero(main_current[4].clone().into() - AB::Expr::ONE); + builder.when_last_row().assert_zero(main_current[6].clone().into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); + builder.when_transition().assert_zero(main_next[1].clone().into()); + builder.when_transition().assert_zero(main_next[2].clone().into() - main_current[2].clone().into()); + builder.when_transition().assert_zero(main_next[5].clone().into() - (main_current[5].clone().into() + AB::Expr::ONE)); + builder.assert_zero(main_current[4].clone().into() - AB::Expr::ONE); } } diff --git a/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs b/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs index 6ab7b74ee..b2f6449e8 100644 --- a/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs +++ b/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,18 +38,22 @@ impl> AirScriptAir for ConstraintCo } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[8].clone().into()); - builder.assert_zero_ext::<_>(main_current[6].clone().into() - main_current[10].clone().into()); - builder.assert_zero_ext::<_>(main_current[7].clone().into() - main_current[11].clone().into()); - builder.assert_zero_ext::<_>(main_current[8].clone().into() - main_current[12].clone().into()); - builder.assert_zero_ext::<_>(main_current[9].clone().into() - main_current[13].clone().into()); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[8].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero(main_current[6].clone().into() - main_current[10].clone().into()); + builder.assert_zero(main_current[7].clone().into() - main_current[11].clone().into()); + builder.assert_zero(main_current[8].clone().into() - main_current[12].clone().into()); + builder.assert_zero(main_current[9].clone().into() - main_current[13].clone().into()); } } diff --git a/air-script/tests/evaluators/evaluators_plonky3.rs b/air-script/tests/evaluators/evaluators_plonky3.rs index b74b6b99f..5761dd95c 100644 --- a/air-script/tests/evaluators/evaluators_plonky3.rs +++ b/air-script/tests/evaluators/evaluators_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,24 +38,28 @@ impl> AirScriptAir for EvaluatorsAi } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - main_current[0].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[2].clone().into() - main_current[2].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[6].clone().into() - main_current[6].clone().into()); - builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); - builder.assert_zero_ext::<_>(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); - builder.assert_zero_ext::<_>(main_current[2].clone().into() * main_current[2].clone().into() - main_current[2].clone().into()); - builder.assert_zero_ext::<_>(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); - builder.assert_zero_ext::<_>(main_current[4].clone().into()); - builder.assert_zero_ext::<_>(main_current[5].clone().into() - AB::Expr::ONE); - builder.assert_zero_ext::<_>(main_current[6].clone().into() - AB::Expr::from_u64(4)); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_next[0].clone().into() - main_current[0].clone().into()); + builder.when_transition().assert_zero(main_next[2].clone().into() - main_current[2].clone().into()); + builder.when_transition().assert_zero(main_next[6].clone().into() - main_current[6].clone().into()); + builder.assert_zero(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.assert_zero(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); + builder.assert_zero(main_current[2].clone().into() * main_current[2].clone().into() - main_current[2].clone().into()); + builder.assert_zero(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); + builder.assert_zero(main_current[4].clone().into()); + builder.assert_zero(main_current[5].clone().into() - AB::Expr::ONE); + builder.assert_zero(main_current[6].clone().into() - AB::Expr::from_u64(4)); } } diff --git a/air-script/tests/fibonacci/fibonacci_plonky3.rs b/air-script/tests/fibonacci/fibonacci_plonky3.rs index baa978c64..5cd24c62c 100644 --- a/air-script/tests/fibonacci/fibonacci_plonky3.rs +++ b/air-script/tests/fibonacci/fibonacci_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,18 +38,22 @@ impl> AirScriptAir for FibonacciAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into() - public_values[0].into()); - builder.when_first_row().assert_zero_ext::<_>(main_current[1].clone().into() - public_values[1].into()); - builder.when_last_row().assert_zero_ext::<_>(main_current[1].clone().into() - public_values[2].into()); - builder.when_transition().assert_zero_ext::<_>(main_next[1].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())); - builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - main_current[1].clone().into()); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into() - public_values[0].into()); + builder.when_first_row().assert_zero(main_current[1].clone().into() - public_values[1].into()); + builder.when_last_row().assert_zero(main_current[1].clone().into() - public_values[2].into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_next[1].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())); + builder.when_transition().assert_zero(main_next[0].clone().into() - main_current[1].clone().into()); } } diff --git a/air-script/tests/functions/functions_complex_plonky3.rs b/air-script/tests/functions/functions_complex_plonky3.rs index 596d2790c..e1b1c46be 100644 --- a/air-script/tests/functions/functions_complex_plonky3.rs +++ b/air-script/tests/functions/functions_complex_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,16 +38,20 @@ impl> AirScriptAir for FunctionsAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[16].clone().into() - main_current[16].clone().into() * ((main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() + main_current[3].clone().into() * main_current[3].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_current[2].clone().into() + main_current[3].clone().into() * main_current[1].clone().into() * (AB::Expr::ONE - main_current[2].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into())) * main_current[0].clone().into() - main_current[0].clone().into() + AB::Expr::ONE)); - builder.when_transition().assert_zero_ext::<_>(main_next[3].clone().into() - (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() + main_current[8].clone().into() + main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() + main_current[14].clone().into() + main_current[15].clone().into() + AB::Expr::ONE).double()); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[3].clone().into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_next[16].clone().into() - main_current[16].clone().into() * ((main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() + main_current[3].clone().into() * main_current[3].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_current[2].clone().into() + main_current[3].clone().into() * main_current[1].clone().into() * (AB::Expr::ONE - main_current[2].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into())) * main_current[0].clone().into() - main_current[0].clone().into() + AB::Expr::ONE)); + builder.when_transition().assert_zero(main_next[3].clone().into() - (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() + main_current[8].clone().into() + main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() + main_current[14].clone().into() + main_current[15].clone().into() + AB::Expr::ONE).double()); } } diff --git a/air-script/tests/functions/functions_simple_plonky3.rs b/air-script/tests/functions/functions_simple_plonky3.rs index 51c279755..61632e6ef 100644 --- a/air-script/tests/functions/functions_simple_plonky3.rs +++ b/air-script/tests/functions/functions_simple_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,22 +38,26 @@ impl> AirScriptAir for FunctionsAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into()); - builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[3].clone().into() - AB::Expr::ONE); - builder.assert_zero_ext::<_>(main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() * main_current[3].clone().into() - AB::Expr::ONE); - builder.assert_zero_ext::<_>((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); - builder.assert_zero_ext::<_>(main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); - builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); - builder.assert_zero_ext::<_>(main_current[1].clone().into() + (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); - builder.assert_zero_ext::<_>(main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() - AB::Expr::ONE); - builder.assert_zero_ext::<_>((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * AB::Expr::from_u64(4) - AB::Expr::ONE); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[3].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero(main_current[0].clone().into() * main_current[3].clone().into() - AB::Expr::ONE); + builder.assert_zero(main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() * main_current[3].clone().into() - AB::Expr::ONE); + builder.assert_zero((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero(main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero(main_current[0].clone().into() * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero(main_current[1].clone().into() + (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero(main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() - AB::Expr::ONE); + builder.assert_zero((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * AB::Expr::from_u64(4) - AB::Expr::ONE); } } diff --git a/air-script/tests/helpers/plonky3_traits.rs b/air-script/tests/helpers/plonky3_traits.rs index d4a1f487d..a9da6a736 100644 --- a/air-script/tests/helpers/plonky3_traits.rs +++ b/air-script/tests/helpers/plonky3_traits.rs @@ -122,10 +122,16 @@ pub struct DebugConstraintBuilderWithAirScriptTraits<'a, F: Field, EF: Extension is_transition: F, /// The periodic columns provided for constraint validation. periodic_columns: Vec, + /// The alpha challenge in the extension field. alpha: EF, + /// The alpha powers in the extension field. alpha_powers: Vec, + /// The beta challenge in the extension field. beta: EF, + /// The aux bus boundary values in the extension field. aux_bus_boundary_values: Vec, + /// The aux trace as a vertical pair. + permutation: VerticalPair, RowMajorMatrixView<'a, EF>>, } impl<'a, F, EF> AirBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> @@ -217,11 +223,11 @@ where type RandomVar = EF; fn permutation(&self) -> Self::MP { - todo!() + self.permutation } fn permutation_randomness(&self) -> &[Self::RandomVar] { - todo!() + self.alpha_powers.as_slice() } } @@ -251,6 +257,96 @@ where } } +fn compute_aux_transition( + main: VerticalPair, RowMajorMatrixView>, + alpha_challenges: Vec, + beta: EF, + aux_current: [EF; 2], +) -> [EF; 2] +where + F: Field, + EF: ExtensionField, +{ + let main_current = &main.row_slice(0).unwrap(); + let _main_next = &main.row_slice(1).unwrap(); + + // First bus: multiset + // p' * multiset_removals = p * multiset_inserts + let multiset_inserts: EF = ((beta + + alpha_challenges[0] + + (EF::from_u64(3) + EF::from(main_current[1].clone())) * alpha_challenges[1] + + EF::from(main_current[0].clone()) * alpha_challenges[2]) + * EF::from(main_current[2].clone()) + + EF::ONE + - EF::from(main_current[2].clone())) + * ((beta + + alpha_challenges[0].double() + + EF::from(main_current[1].clone()) * alpha_challenges[1]) + * (EF::ONE - EF::from(main_current[2].clone())) + + EF::from(main_current[2].clone())); + let multiset_removals: EF = ((beta + + alpha_challenges[0] + + (EF::from_u64(3) + EF::from(main_current[1].clone())) * alpha_challenges[1] + + EF::from(main_current[1].clone()) * alpha_challenges[2]) + * EF::from(main_current[3].clone()) + + EF::ONE + - EF::from(main_current[3].clone())) + * ((beta + + alpha_challenges[0].double() + + EF::from(main_current[0].clone()) * alpha_challenges[1]) + * (EF::ONE - EF::from(main_current[3].clone())) + + EF::from(main_current[3].clone())); + let multiset_current = EF::from(aux_current[0].clone()); + let multiset_next = multiset_current * multiset_inserts * multiset_removals.inverse(); + + // Second bus: logup + // 0 = A * q + B + C - D * q' - E; + let a: EF = (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[0].clone()) * alpha_challenges[1]) + * (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[0].clone()) * alpha_challenges[1]) + * (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[1].clone()) * alpha_challenges[1]); + let b: EF = (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[0].clone()) * alpha_challenges[1]) + * (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[1].clone()) * alpha_challenges[1]) + * EF::from(main_current[4].clone()); + let c: EF = (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[0].clone()) * alpha_challenges[1]) + * (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[1].clone()) * alpha_challenges[1]) + * EF::from(main_current[5].clone()); + let d: EF = (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[0].clone()) * alpha_challenges[1]) + * (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[0].clone()) * alpha_challenges[1]) + * (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[1].clone()) * alpha_challenges[1]); + let e: EF = (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[0].clone()) * alpha_challenges[1]) + * (beta + + EF::from_u64(3) * alpha_challenges[0] + + EF::from(main_current[0].clone()) * alpha_challenges[1]) + * EF::from(main_current[6].clone()); + let logup_current = EF::from(aux_current[1].clone()); + let logup_next = (a * logup_current + b + c - e) * d.inverse(); + + // Dummy implementation for illustration purposes. + [multiset_next, logup_next] +} + pub(crate) fn check_constraints_with_airscript_traits( air: &A, main: &RowMajorMatrix, @@ -263,22 +359,42 @@ pub(crate) fn check_constraints_with_airscript_traits( { let height = main.height(); + let aux_bus_boundary_values: Vec<_> = (0..air.aux_width()).map(|_| EF::GENERATOR).collect(); + let alpha = EF::from_u64(123456789); + let beta = EF::from_u64(987654321); + let alpha_powers: Vec = (0..air.num_alpha_challenges()) + .map(|power| alpha.exp_u64(power as u64)) + .collect(); + + let initial_aux = [EF::ONE, EF::ZERO]; + + let mut current_aux_values = initial_aux.clone(); + (0..height).for_each(|i| { let i_next = (i + 1) % height; - let local = main.row_slice(i).unwrap(); // i < height so unwrap should never fail. - let next = main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail. + let main_local = main.row_slice(i).unwrap(); // i < height so unwrap should never fail. + let main_next = main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail. let main = VerticalPair::new( - RowMajorMatrixView::new_row(&*local), - RowMajorMatrixView::new_row(&*next), + RowMajorMatrixView::new_row(&*main_local), + RowMajorMatrixView::new_row(&*main_next), ); + let periodic_columns_base: Vec<_> = air.periodic_table().iter().map(|col| col[i % col.len()]).collect(); let periodic_columns: Vec = periodic_columns_base.iter().map(|&v| EF::from(v)).collect(); - let aux_bus_boundary_values: Vec<_> = (0..air.aux_width()).map(|_| EF::GENERATOR).collect(); - let alpha = EF::GENERATOR; // TODO - let beta = EF::GENERATOR; // TODO + + let aux_local = current_aux_values; + if air.aux_width() > 0 && i != height - 1 { + current_aux_values = + compute_aux_transition::(main, alpha_powers.clone(), beta, aux_local); + } + let aux_next = current_aux_values; + let aux = VerticalPair::new( + RowMajorMatrixView::new_row(&aux_local), + RowMajorMatrixView::new_row(&aux_next), + ); let mut builder = DebugConstraintBuilderWithAirScriptTraits { row_index: i, @@ -290,10 +406,9 @@ pub(crate) fn check_constraints_with_airscript_traits( periodic_columns, alpha, beta, - alpha_powers: (0..air.num_alpha_challenges()) - .map(|power| alpha.exp_u64(power as u64)) - .collect(), - aux_bus_boundary_values, + alpha_powers: alpha_powers.clone(), + aux_bus_boundary_values: aux_bus_boundary_values.clone(), + permutation: aux, }; AirScriptAir::eval(air, &mut builder); diff --git a/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs b/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs index d314f4927..1753a4967 100644 --- a/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs +++ b/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,15 +38,19 @@ impl> AirScriptAir for TraceAccessA } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - (main_current[1].clone().into() + AB::Expr::ONE)); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_next[0].clone().into() - (main_current[1].clone().into() + AB::Expr::ONE)); } } diff --git a/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs b/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs index 4a693aa6f..94cc649b9 100644 --- a/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs +++ b/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,17 +38,21 @@ impl> AirScriptAir for ListComprehe } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); - builder.assert_zero_ext::<_>(main_current[0].clone().into() + main_current[1].clone().into().double() - AB::Expr::from_u64(3)); - builder.assert_zero_ext::<_>(main_current[0].clone().into().double() + main_current[1].clone().into() * AB::Expr::from_u64(3) - AB::Expr::from_u64(5)); - builder.assert_zero_ext::<_>(main_current[0].clone().into() * AB::Expr::from_u64(3) + main_current[1].clone().into() * AB::Expr::from_u64(4) - AB::Expr::from_u64(7)); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero(main_current[0].clone().into() + main_current[1].clone().into().double() - AB::Expr::from_u64(3)); + builder.assert_zero(main_current[0].clone().into().double() + main_current[1].clone().into() * AB::Expr::from_u64(3) - AB::Expr::from_u64(5)); + builder.assert_zero(main_current[0].clone().into() * AB::Expr::from_u64(3) + main_current[1].clone().into() * AB::Expr::from_u64(4) - AB::Expr::from_u64(7)); } } diff --git a/air-script/tests/list_comprehension/list_comprehension_plonky3.rs b/air-script/tests/list_comprehension/list_comprehension_plonky3.rs index 8b853068d..7157d6c28 100644 --- a/air-script/tests/list_comprehension/list_comprehension_plonky3.rs +++ b/air-script/tests/list_comprehension/list_comprehension_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,20 +38,24 @@ impl> AirScriptAir for ListComprehe } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[10].clone().into()); - builder.assert_zero_ext::<_>(main_current[0].clone().into() - main_current[2].clone().into()); - builder.assert_zero_ext::<_>(main_current[4].clone().into() - main_current[0].clone().into() * AB::Expr::from_u64(8) * main_current[11].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_current[4].clone().into() - main_current[0].clone().into() * (main_next[8].clone().into() - main_next[12].clone().into())); - builder.assert_zero_ext::<_>(main_current[6].clone().into() - main_current[0].clone().into() * (main_current[9].clone().into() - main_current[14].clone().into())); - builder.assert_zero_ext::<_>(main_current[1].clone().into() - (main_current[5].clone().into() - main_current[8].clone().into() - main_current[12].clone().into() + AB::Expr::from_u64(10) + main_current[6].clone().into() - main_current[9].clone().into() - main_current[13].clone().into() + AB::Expr::from_u64(20) + main_current[7].clone().into() - main_current[10].clone().into() - main_current[14].clone().into())); - builder.assert_zero_ext::<_>(main_current[14].clone().into() - AB::Expr::from_u64(10)); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[10].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero(main_current[0].clone().into() - main_current[2].clone().into()); + builder.assert_zero(main_current[4].clone().into() - main_current[0].clone().into() * AB::Expr::from_u64(8) * main_current[11].clone().into()); + builder.when_transition().assert_zero(main_current[4].clone().into() - main_current[0].clone().into() * (main_next[8].clone().into() - main_next[12].clone().into())); + builder.assert_zero(main_current[6].clone().into() - main_current[0].clone().into() * (main_current[9].clone().into() - main_current[14].clone().into())); + builder.assert_zero(main_current[1].clone().into() - (main_current[5].clone().into() - main_current[8].clone().into() - main_current[12].clone().into() + AB::Expr::from_u64(10) + main_current[6].clone().into() - main_current[9].clone().into() - main_current[13].clone().into() + AB::Expr::from_u64(20) + main_current[7].clone().into() - main_current[10].clone().into() - main_current[14].clone().into())); + builder.assert_zero(main_current[14].clone().into() - AB::Expr::from_u64(10)); } } diff --git a/air-script/tests/list_folding/list_folding_plonky3.rs b/air-script/tests/list_folding/list_folding_plonky3.rs index eab864003..bb974c90e 100644 --- a/air-script/tests/list_folding/list_folding_plonky3.rs +++ b/air-script/tests/list_folding/list_folding_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,18 +38,22 @@ impl> AirScriptAir for ListFoldingA } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[11].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[5].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); - builder.when_transition().assert_zero_ext::<_>(main_next[6].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); - builder.when_transition().assert_zero_ext::<_>(main_next[7].clone().into() - (main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + (main_current[9].clone().into() + main_current[13].clone().into()) * (main_current[10].clone().into() + main_current[14].clone().into()) * (main_current[11].clone().into() + main_current[15].clone().into()) * (main_current[12].clone().into() + main_current[16].clone().into()))); - builder.when_transition().assert_zero_ext::<_>(main_next[8].clone().into() - (main_current[1].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into())); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[11].clone().into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_next[5].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); + builder.when_transition().assert_zero(main_next[6].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); + builder.when_transition().assert_zero(main_next[7].clone().into() - (main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + (main_current[9].clone().into() + main_current[13].clone().into()) * (main_current[10].clone().into() + main_current[14].clone().into()) * (main_current[11].clone().into() + main_current[15].clone().into()) * (main_current[12].clone().into() + main_current[16].clone().into()))); + builder.when_transition().assert_zero(main_next[8].clone().into() - (main_current[1].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into())); } } diff --git a/air-script/tests/periodic_columns/periodic_columns_plonky3.rs b/air-script/tests/periodic_columns/periodic_columns_plonky3.rs index 688221f5a..32c6fbcd0 100644 --- a/air-script/tests/periodic_columns/periodic_columns_plonky3.rs +++ b/air-script/tests/periodic_columns/periodic_columns_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -41,16 +41,20 @@ impl> AirScriptAir for PeriodicColu } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); - builder.assert_zero_ext::<_>(periodic_values[0].into() * (main_current[1].clone().into() + main_current[2].clone().into())); - builder.when_transition().assert_zero_ext::<_>(periodic_values[1].into() * (main_next[0].clone().into() - main_current[0].clone().into())); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero_ext(periodic_values[0].into() * (AB::ExprEF::from(main_current[1].clone().into()) + AB::ExprEF::from(main_current[2].clone().into()))); + builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); } } diff --git a/air-script/tests/pub_inputs/pub_inputs_plonky3.rs b/air-script/tests/pub_inputs/pub_inputs_plonky3.rs index 96b3bb6da..c5c01e5af 100644 --- a/air-script/tests/pub_inputs/pub_inputs_plonky3.rs +++ b/air-script/tests/pub_inputs/pub_inputs_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,22 +38,26 @@ impl> AirScriptAir for PubInputsAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into() - public_values[8].into()); - builder.when_first_row().assert_zero_ext::<_>(main_current[1].clone().into() - public_values[9].into()); - builder.when_first_row().assert_zero_ext::<_>(main_current[2].clone().into() - public_values[10].into()); - builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into() - public_values[11].into()); - builder.when_last_row().assert_zero_ext::<_>(main_current[0].clone().into() - public_values[12].into()); - builder.when_last_row().assert_zero_ext::<_>(main_current[1].clone().into() - public_values[13].into()); - builder.when_last_row().assert_zero_ext::<_>(main_current[2].clone().into() - public_values[14].into()); - builder.when_last_row().assert_zero_ext::<_>(main_current[3].clone().into() - public_values[15].into()); - builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - (main_current[1].clone().into() + main_current[2].clone().into())); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into() - public_values[8].into()); + builder.when_first_row().assert_zero(main_current[1].clone().into() - public_values[9].into()); + builder.when_first_row().assert_zero(main_current[2].clone().into() - public_values[10].into()); + builder.when_first_row().assert_zero(main_current[3].clone().into() - public_values[11].into()); + builder.when_last_row().assert_zero(main_current[0].clone().into() - public_values[12].into()); + builder.when_last_row().assert_zero(main_current[1].clone().into() - public_values[13].into()); + builder.when_last_row().assert_zero(main_current[2].clone().into() - public_values[14].into()); + builder.when_last_row().assert_zero(main_current[3].clone().into() - public_values[15].into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_next[0].clone().into() - (main_current[1].clone().into() + main_current[2].clone().into())); } } diff --git a/air-script/tests/selectors/selectors_combine_complex_plonky3.rs b/air-script/tests/selectors/selectors_combine_complex_plonky3.rs index aebac82ba..4d0ab6a34 100644 --- a/air-script/tests/selectors/selectors_combine_complex_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_complex_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 1; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_ALPHA_CHALLENGES: usize = 3; +pub const NUM_ALPHA_CHALLENGES: usize = 2; pub struct SelectorsAir; @@ -38,17 +38,36 @@ impl> AirScriptAir for SelectorsAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[5].clone().into()); - builder.assert_zero_ext::<_>((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * (main_current[3].clone().into() - AB::Expr::from_u64(16)) + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(5))); - builder.assert_zero_ext::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(5)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(4))); - builder.assert_zero_ext::<_>(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(20)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(31))); + let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); + let beta = builder.beta(); + let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); + let aux = builder.permutation(); + let (aux_current, aux_next) = ( + aux.row_slice(0).unwrap(), + aux.row_slice(1).unwrap(), + ); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[5].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * (main_current[3].clone().into() - AB::Expr::from_u64(16)) + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(5))); + builder.assert_zero((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(5)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(4))); + builder.assert_zero(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(20)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(31))); + + // Aux boundary constraints + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); + + // Aux integrity/transition constraints + builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into()) * AB::ExprEF::from(main_current[5].clone().into())) * ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(main_current[1].clone().into()) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::ONE - (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(main_current[1].clone().into()) * AB::ExprEF::from(main_current[5].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from_u64(4) * alpha_challenges[1].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[1].clone().into())) * AB::ExprEF::from(main_current[4].clone().into()) + AB::ExprEF::ONE - (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[1].clone().into())) * AB::ExprEF::from(main_current[4].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); } } diff --git a/air-script/tests/selectors/selectors_combine_simple_plonky3.rs b/air-script/tests/selectors/selectors_combine_simple_plonky3.rs index 022d2e452..50b2cda0d 100644 --- a/air-script/tests/selectors/selectors_combine_simple_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_simple_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,16 +38,20 @@ impl> AirScriptAir for SelectorsAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[1].clone().into() - main_current[2].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_current[3].clone().into() * (main_next[0].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())) + (AB::Expr::ONE - main_current[3].clone().into()) * (main_next[0].clone().into() - main_current[0].clone().into() * main_current[1].clone().into())); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[3].clone().into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_next[1].clone().into() - main_current[2].clone().into()); + builder.when_transition().assert_zero(main_current[3].clone().into() * (main_next[0].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())) + (AB::Expr::ONE - main_current[3].clone().into()) * (main_next[0].clone().into() - main_current[0].clone().into() * main_current[1].clone().into())); } } diff --git a/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs b/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs index 252b99427..5cc70b27a 100644 --- a/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs +++ b/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,17 +38,21 @@ impl> AirScriptAir for SelectorsAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[5].clone().into()); - builder.assert_zero_ext::<_>((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * main_current[3].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(8))); - builder.assert_zero_ext::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(8)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(2))); - builder.assert_zero_ext::<_>(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(4)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(6))); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[5].clone().into()); + + // Main integrity/transition constraints + builder.assert_zero((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * main_current[3].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(8))); + builder.assert_zero((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(8)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(2))); + builder.assert_zero(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(4)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(6))); } } diff --git a/air-script/tests/selectors/selectors_plonky3.rs b/air-script/tests/selectors/selectors_plonky3.rs index ce51e091e..a0d6c8bee 100644 --- a/air-script/tests/selectors/selectors_plonky3.rs +++ b/air-script/tests/selectors/selectors_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,16 +38,20 @@ impl> AirScriptAir for SelectorsAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_current[0].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[3].clone().into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); + builder.when_transition().assert_zero(main_current[0].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); } } diff --git a/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs b/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs index bce55dfbd..82bbc21c8 100644 --- a/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs +++ b/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,16 +38,20 @@ impl> AirScriptAir for SelectorsAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[3].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_current[1].clone().into() * main_current[2].clone().into() * main_current[0].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[3].clone().into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); + builder.when_transition().assert_zero(main_current[1].clone().into() * main_current[2].clone().into() * main_current[0].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); } } diff --git a/air-script/tests/system/system_plonky3.rs b/air-script/tests/system/system_plonky3.rs index 1ec96a91c..a6eaad01b 100644 --- a/air-script/tests/system/system_plonky3.rs +++ b/air-script/tests/system/system_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,15 +38,19 @@ impl> AirScriptAir for SystemAir { } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[0].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[0].clone().into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); } } diff --git a/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs b/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs index ee2ddb74d..cb01541fa 100644 --- a/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs +++ b/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -38,16 +38,20 @@ impl> AirScriptAir for TraceColGrou } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[8].clone().into()); - builder.when_transition().assert_zero_ext::<_>(main_next[2].clone().into() - (main_current[2].clone().into() + AB::Expr::ONE)); - builder.when_transition().assert_zero_ext::<_>(main_next[1].clone().into() - (main_current[1].clone().into() - AB::Expr::ONE)); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[8].clone().into()); + + // Main integrity/transition constraints + builder.when_transition().assert_zero(main_next[2].clone().into() - (main_current[2].clone().into() + AB::Expr::ONE)); + builder.when_transition().assert_zero(main_next[1].clone().into() - (main_current[1].clone().into() - AB::Expr::ONE)); } } diff --git a/air-script/tests/variables/variables_plonky3.rs b/air-script/tests/variables/variables_plonky3.rs index 66831b1c3..0f0da0331 100644 --- a/air-script/tests/variables/variables_plonky3.rs +++ b/air-script/tests/variables/variables_plonky3.rs @@ -1,4 +1,4 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; use crate::helpers::{AirScriptAir, AirScriptBuilder}; @@ -40,19 +40,23 @@ impl> AirScriptAir for VariablesAir } fn eval(&self, builder: &mut AB) { - let main = builder.main(); let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - builder.when_first_row().assert_zero_ext::<_>(main_current[1].clone().into()); - builder.when_last_row().assert_zero_ext::<_>(main_current[1].clone().into() - AB::Expr::ONE); - builder.assert_zero_ext::<_>(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); - builder.when_transition().assert_zero_ext::<_>(periodic_values[0].into() * (main_next[0].clone().into() - main_current[0].clone().into())); - builder.assert_zero_ext::<_>((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[3].clone().into() - main_current[1].clone().into() - main_current[2].clone().into()) - (AB::Expr::from_u64(6) - (AB::Expr::from_u64(7) - main_current[0].clone().into()))); - builder.when_transition().assert_zero_ext::<_>(main_current[0].clone().into() * (main_current[3].clone().into() - main_current[1].clone().into() * main_current[2].clone().into()) - (AB::Expr::ONE - main_next[0].clone().into())); + + // Main boundary constraints + builder.when_first_row().assert_zero(main_current[1].clone().into()); + builder.when_last_row().assert_zero(main_current[1].clone().into() - AB::Expr::ONE); + + // Main integrity/transition constraints + builder.assert_zero(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); + builder.when_transition().assert_zero_ext(periodic_values[0].into() * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); + builder.assert_zero((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[3].clone().into() - main_current[1].clone().into() - main_current[2].clone().into()) - (AB::Expr::from_u64(6) - (AB::Expr::from_u64(7) - main_current[0].clone().into()))); + builder.when_transition().assert_zero(main_current[0].clone().into() * (main_current[3].clone().into() - main_current[1].clone().into() * main_current[2].clone().into()) - (AB::Expr::ONE - main_next[0].clone().into())); } } diff --git a/air/src/passes/expand_buses.rs b/air/src/passes/expand_buses.rs index ff02487dd..6c7780c3d 100644 --- a/air/src/passes/expand_buses.rs +++ b/air/src/passes/expand_buses.rs @@ -234,8 +234,11 @@ impl<'a> BusOpExpand<'a> { // 6. Create the resulting constraint and insert it into the graph let root = graph.insert_node(Operation::Sub(p_prod, p_prime_prod)); - ir.constraints - .insert_constraint(TraceSegmentId::Aux, root, ConstraintDomain::EveryRow); + ir.constraints.insert_constraint( + TraceSegmentId::Aux, + root, + ConstraintDomain::EveryFrame(2), + ); } /// Helper function to expand the integrity constraint of a logup bus @@ -372,7 +375,10 @@ impl<'a> BusOpExpand<'a> { // 5. Create the resulting constraint let root = graph.insert_node(Operation::Sub(q_term, q_prime_term)); - ir.constraints - .insert_constraint(TraceSegmentId::Aux, root, ConstraintDomain::EveryRow); + ir.constraints.insert_constraint( + TraceSegmentId::Aux, + root, + ConstraintDomain::EveryFrame(2), + ); } } diff --git a/codegen/plonky3/src/air/boundary_constraints.rs b/codegen/plonky3/src/air/boundary_constraints.rs index 79b0278a2..89da2bf5b 100644 --- a/codegen/plonky3/src/air/boundary_constraints.rs +++ b/codegen/plonky3/src/air/boundary_constraints.rs @@ -1,24 +1,49 @@ use air_ir::{Air, TraceSegmentId}; use codegen::Function; -use super::Codegen; +use crate::air::graph::constraint_to_string; /// Adds the main boundary constraints to the generated code. pub(super) fn add_main_boundary_constraints(eval_func: &mut Function, ir: &Air) { - for constraint in ir.boundary_constraints(TraceSegmentId::Main) { - let expr_root = constraint.node_index(); - - let expr_root_string = expr_root.to_string(ir); - - let assertion = match constraint.domain() { - air_ir::ConstraintDomain::FirstRow => { - format!("builder.when_first_row().assert_zero_ext::<_>({expr_root_string});") - }, - air_ir::ConstraintDomain::LastRow => { - format!("builder.when_last_row().assert_zero_ext::<_>({expr_root_string});") - }, - _ => unreachable!("Boundary constraints can only be applied to the first or last row"), - }; + let constraints = ir.boundary_constraints(TraceSegmentId::Main); + if !constraints.is_empty() { + eval_func.line(""); + eval_func.line("// Main boundary constraints"); + } + for constraint in constraints { + let assertion = constraint_to_string(ir, constraint, true); + eval_func.line(assertion); + } +} + +/// Adds the aux boundary constraints to the generated code. +pub(super) fn add_aux_boundary_constraints(eval_func: &mut Function, ir: &Air) { + let constraints = ir.boundary_constraints(TraceSegmentId::Aux); + if !constraints.is_empty() { + eval_func.line(""); + eval_func.line("// Aux boundary constraints"); + } + for constraint in constraints { + let assertion = constraint_to_string(ir, constraint, true); eval_func.line(assertion); + + // TODO: add code to handle aux boundary constraints + + /*// For first row constraints, we can use `when_first_row` to conditionally apply the assertion + if constraint.domain() == ConstraintDomain::FirstRow { + let expr_root = constraint.node_index(); + let expr_root_string = expr_root.to_string(ir, ElemType::Ext); + + let assertion = format!("builder.when_first_row().assert_zero_ext({expr_root_string});"); + eval_func.line(assertion); + } else { + let assertion = constraint_to_string(ir, constraint, false); + + let domain_flag = get_domain_flag_str(&constraint.domain()); + let extension_field_flag = get_extension_field_flag_str(ir, *expr_root); + let assertion = format!("builder{domain_flag}.assert_zero{extension_field_flag}({expr_root_string});"); + + eval_func.line(assertion); + }*/ } } diff --git a/codegen/plonky3/src/air/graph.rs b/codegen/plonky3/src/air/graph.rs index 339ec5ca0..72d623e09 100644 --- a/codegen/plonky3/src/air/graph.rs +++ b/codegen/plonky3/src/air/graph.rs @@ -1,4 +1,8 @@ -use air_ir::{Air, NodeIndex, Operation, TraceAccess, Value}; +use air_ir::{ + Air, ConstraintDomain, ConstraintRoot, NodeIndex, Operation, TraceAccess, TraceSegmentId, Value, +}; + +use crate::air::ElemType; // RUST STRING GENERATION FOR THE CONSTRAINT GRAPH // ================================================================================================ @@ -6,50 +10,62 @@ use air_ir::{Air, NodeIndex, Operation, TraceAccess, Value}; /// Code generation trait for generating Rust code strings from IR types related to constraints and /// the [AlgebraicGraph]. pub trait Codegen { - fn to_string(&self, ir: &Air) -> String; + fn to_string(&self, ir: &Air, elem_type: ElemType) -> String; } impl Codegen for TraceAccess { - fn to_string(&self, _ir: &Air) -> String { + fn to_string(&self, _ir: &Air, elem_type: ElemType) -> String { let frame = self.segment.to_string(); let row_offset = match self.row_offset { 0 => { - format!("current[{}].clone().into()", self.column) + format!("current[{}]", self.column) }, 1 => { - format!("next[{}].clone().into()", self.column) + format!("next[{}]", self.column) }, _ => panic!("Plonky3 doesn't support row offsets greater than 1."), }; - format!("{frame}_{row_offset}") + match elem_type { + ElemType::Base => format!("{frame}_{row_offset}.clone().into()"), + ElemType::Ext => format!("AB::ExprEF::from({frame}_{row_offset}.clone().into())"), + } } } impl Codegen for NodeIndex { - fn to_string(&self, ir: &Air) -> String { + fn to_string(&self, ir: &Air, elem_type: ElemType) -> String { let op = ir.constraint_graph().node(self).op(); - op.to_string(ir) + op.to_string(ir, elem_type) } } impl Codegen for Operation { - fn to_string(&self, ir: &Air) -> String { + fn to_string(&self, ir: &Air, elem_type: ElemType) -> String { match self { - Operation::Value(value) => value.to_string(ir), - Operation::Add(..) => binary_op_to_string(ir, self), - Operation::Sub(..) => binary_op_to_string(ir, self), - Operation::Mul(..) => binary_op_to_string(ir, self), + Operation::Value(value) => value.to_string(ir, elem_type), + Operation::Add(..) => binary_op_to_string(ir, elem_type, self), + Operation::Sub(..) => binary_op_to_string(ir, elem_type, self), + Operation::Mul(..) => binary_op_to_string(ir, elem_type, self), } } } impl Codegen for Value { - fn to_string(&self, ir: &Air) -> String { + fn to_string(&self, ir: &Air, elem_type: ElemType) -> String { match self { - Value::Constant(0) => format!("AB::Expr::ZERO"), - Value::Constant(1) => format!("AB::Expr::ONE"), - Value::Constant(value) => format!("AB::Expr::from_u64({value})"), - Value::TraceAccess(trace_access) => trace_access.to_string(ir), + Value::Constant(0) => match elem_type { + ElemType::Base => format!("AB::Expr::ZERO"), + ElemType::Ext => format!("AB::ExprEF::ZERO"), + }, + Value::Constant(1) => match elem_type { + ElemType::Base => format!("AB::Expr::ONE"), + ElemType::Ext => format!("AB::ExprEF::ONE"), + }, + Value::Constant(value) => match elem_type { + ElemType::Base => format!("AB::Expr::from_u64({value})"), + ElemType::Ext => format!("AB::ExprEF::from_u64({value})"), + }, + Value::TraceAccess(trace_access) => trace_access.to_string(ir, elem_type), Value::PublicInput(air_ir::PublicInputAccess { name, index }) => { let get_public_input_offset = |name: &str| { ir.public_inputs() @@ -64,35 +80,39 @@ impl Codegen for Value { ir.periodic_columns.iter().position(|(qid, _)| qid == &pc.name).unwrap(); format!("periodic_values[{index}].into()") }, - _ => todo!(), - /*Value::PublicInputTable(air_ir::PublicInputTableAccess { - table_name, - bus_type, - num_cols: _, - }) => { - format!("reduced_{table_name}_{bus_type}") + Value::PublicInputTable(public_input_table_access) => { + let idx = ir + .reduced_public_input_table_accesses() + .iter() + .position(|pi| pi == public_input_table_access) + .unwrap(); + format!("aux_bus_boundary_values[{idx}].into()") }, Value::RandomValue(idx) => { - format!("aux_rand_elements.rand_elements()[{idx}]") - },*/ + if *idx == 0 { + format!("beta.into()") + } else { + format!("alpha_challenges[{}].into()", idx - 1) + } + }, } } } /// Returns a string representation of a binary operation. -fn binary_op_to_string(ir: &Air, op: &Operation) -> String { +fn binary_op_to_string(ir: &Air, elem_type: ElemType, op: &Operation) -> String { match op { Operation::Add(l_idx, r_idx) => { - let lhs = l_idx.to_string(ir); - let rhs = r_idx.to_string(ir); + let lhs = l_idx.to_string(ir, elem_type); + let rhs = r_idx.to_string(ir, elem_type); format!("{lhs} + {rhs}") }, Operation::Sub(l_idx, r_idx) => { - let lhs = l_idx.to_string(ir); + let lhs = l_idx.to_string(ir, elem_type); let rhs = if ir.constraint_graph().node(r_idx).op().precedence() <= op.precedence() { - format!("({})", r_idx.to_string(ir)) + format!("({})", r_idx.to_string(ir, elem_type)) } else { - r_idx.to_string(ir) + r_idx.to_string(ir, elem_type) }; format!("{lhs} - {rhs}") }, @@ -101,14 +121,14 @@ fn binary_op_to_string(ir: &Air, op: &Operation) -> String { let rhs_op = ir.constraint_graph().node(r_idx).op(); let lhs = if lhs_op.precedence() < op.precedence() { - format!("({})", l_idx.to_string(ir)) + format!("({})", l_idx.to_string(ir, elem_type)) } else { - l_idx.to_string(ir) + l_idx.to_string(ir, elem_type) }; let rhs = if rhs_op.precedence() < op.precedence() { - format!("({})", r_idx.to_string(ir)) + format!("({})", r_idx.to_string(ir, elem_type)) } else { - r_idx.to_string(ir) + r_idx.to_string(ir, elem_type) }; match (lhs_op, rhs_op) { @@ -120,3 +140,63 @@ fn binary_op_to_string(ir: &Air, op: &Operation) -> String { _ => panic!("unsupported operation"), } } + +/// Recursively determines if the expression depends on extension field values (i.e., aux trace, +/// random values, periodic columns, or public input tables). +pub fn needs_extension_field(ir: &Air, expr_root: NodeIndex) -> bool { + let op = ir.constraint_graph().node(&expr_root).op(); + match op { + Operation::Value(value) => match value { + Value::TraceAccess(trace_access) => trace_access.segment == TraceSegmentId::Aux, + Value::Constant(_) => false, + Value::PeriodicColumn(_) => true, + Value::PublicInput(_) => false, + Value::PublicInputTable(_) => true, + Value::RandomValue(_) => true, + }, + Operation::Add(lhs, rhs) | Operation::Sub(lhs, rhs) | Operation::Mul(lhs, rhs) => { + needs_extension_field(ir, *lhs) || needs_extension_field(ir, *rhs) + }, + } +} + +/// Returns the appropriate domain flag string for the given [ConstraintDomain]. +fn get_boundary_domain_flag_str(domain: &ConstraintDomain) -> &'static str { + match domain { + ConstraintDomain::FirstRow => ".when_first_row()", + ConstraintDomain::LastRow => ".when_last_row()", + _ => unreachable!("Invalid domain for boundary constraints"), + } +} + +/// Returns the appropriate domain flag string for the given [ConstraintDomain]. +fn get_integrity_domain_flag_str(domain: &ConstraintDomain) -> &'static str { + match domain { + ConstraintDomain::EveryFrame(_) => ".when_transition()", + ConstraintDomain::EveryRow => "", + _ => unreachable!("Invalid domain for integrity constraints"), + } +} + +pub fn constraint_to_string(ir: &Air, constraint: &ConstraintRoot, in_boundary: bool) -> String { + let expr_root = constraint.node_index(); + let needs_extension_field = needs_extension_field(ir, *expr_root); + let elem_type = if needs_extension_field { + ElemType::Ext + } else { + ElemType::Base + }; + let expr_root_string = expr_root.to_string(ir, elem_type); + + // If the constraint is a transition constraint (depends on the next row), we do not + // evaluate it in the last row, with the `when_transition` method. + let domain_flag = if in_boundary { + get_boundary_domain_flag_str(&constraint.domain()) + } else { + get_integrity_domain_flag_str(&constraint.domain()) + }; + let extension_field_flag = if needs_extension_field { "_ext" } else { "" }; + let assertion = + format!("builder{domain_flag}.assert_zero{extension_field_flag}({expr_root_string});"); + assertion +} diff --git a/codegen/plonky3/src/air/integrity_constraints.rs b/codegen/plonky3/src/air/integrity_constraints.rs index 07e6a396c..074a7ee3c 100644 --- a/codegen/plonky3/src/air/integrity_constraints.rs +++ b/codegen/plonky3/src/air/integrity_constraints.rs @@ -1,22 +1,30 @@ -use air_ir::{Air, ConstraintDomain, TraceSegmentId}; +use air_ir::{Air, TraceSegmentId}; use codegen::Function; -use super::Codegen; +use crate::air::graph::constraint_to_string; /// Adds the main integrity constraints to the generated code. pub(super) fn add_main_integrity_constraints(eval_func: &mut Function, ir: &Air) { - for constraint in ir.integrity_constraints(TraceSegmentId::Main) { - let expr_root = constraint.node_index(); - let expr_root_string = expr_root.to_string(ir); - - // If the constraint is a transition constraint (depends on the next row), we do not - // evaluate it in the last row, with the `when_transition` method. - let assertion = if let ConstraintDomain::EveryFrame(_) = constraint.domain() { - format!("builder.when_transition().assert_zero_ext::<_>({expr_root_string});") - } else { - format!("builder.assert_zero_ext::<_>({expr_root_string});") - }; + let constraints = ir.integrity_constraints(TraceSegmentId::Main); + if !constraints.is_empty() { + eval_func.line(""); + eval_func.line("// Main integrity/transition constraints"); + } + for constraint in constraints { + let assertion = constraint_to_string(ir, constraint, false); + eval_func.line(assertion); + } +} +/// Adds the aux integrity constraints to the generated code. +pub(super) fn add_aux_integrity_constraints(eval_func: &mut Function, ir: &Air) { + let constraints = ir.integrity_constraints(TraceSegmentId::Aux); + if !constraints.is_empty() { + eval_func.line(""); + eval_func.line("// Aux integrity/transition constraints"); + } + for constraint in constraints { + let assertion = constraint_to_string(ir, constraint, false); eval_func.line(assertion); } } diff --git a/codegen/plonky3/src/air/mod.rs b/codegen/plonky3/src/air/mod.rs index 4a54ec23b..21a1239a6 100644 --- a/codegen/plonky3/src/air/mod.rs +++ b/codegen/plonky3/src/air/mod.rs @@ -1,16 +1,21 @@ mod boundary_constraints; mod graph; -use graph::Codegen; mod integrity_constraints; use air_ir::Air; use super::Scope; use crate::air::{ - boundary_constraints::add_main_boundary_constraints, - integrity_constraints::add_main_integrity_constraints, + boundary_constraints::{add_aux_boundary_constraints, add_main_boundary_constraints}, + integrity_constraints::{add_aux_integrity_constraints, add_main_integrity_constraints}, }; +#[derive(Debug, Clone, Copy)] +pub enum ElemType { + Base, + Ext, +} + // HELPERS TO GENERATE AN IMPLEMENTATION OF THE PLONKY3 AIR TRAIT // ================================================================================================ @@ -41,7 +46,7 @@ fn add_constants(scope: &mut Scope, ir: &Air) { let period = ir.periodic_columns().map(|col| col.period()).max().unwrap_or(0); let num_public_values = ir.public_inputs().map(|public_input| public_input.size()).sum::(); - let num_alpha_challenges = ir.num_random_values; + let num_alpha_challenges = ir.num_random_values.saturating_sub(1); let constants = [ format!("pub const MAIN_WIDTH: usize = {main_width};"), @@ -119,21 +124,33 @@ fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { // add the eval function let eval_func = air_script_impl.new_fn("eval").arg_ref_self().arg("builder", "&mut AB"); - eval_func.line("let main = builder.main();"); eval_func.line("let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect(\"Wrong number of public values\");"); eval_func.line("let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect(\"Wrong number of periodic values\");"); + eval_func.line("let main = builder.main();"); eval_func.line("let (main_current, main_next) = ("); eval_func.line(" main.row_slice(0).unwrap(),"); eval_func.line(" main.row_slice(1).unwrap(),"); eval_func.line(");"); - eval_func.line(""); - eval_func.line("// Main boundary constraints"); + // Only had aux if there are random values + if ir.num_random_values > 0 { + eval_func.line("let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect(\"Wrong number of alpha challenges\");"); + eval_func.line("let beta = builder.beta();"); + eval_func.line("let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect(\"Wrong number of aux bus boundary values\");"); + eval_func.line("let aux = builder.permutation();"); + eval_func.line("let (aux_current, aux_next) = ("); + eval_func.line(" aux.row_slice(0).unwrap(),"); + eval_func.line(" aux.row_slice(1).unwrap(),"); + eval_func.line(");"); + } + add_main_boundary_constraints(eval_func, ir); - eval_func.line(""); - eval_func.line("// Main integrity/transition constraints"); add_main_integrity_constraints(eval_func, ir); + + add_aux_boundary_constraints(eval_func, ir); + + add_aux_integrity_constraints(eval_func, ir); } /// Updates the provided scope with the custom Air struct and an Air trait implementation based on diff --git a/codegen/plonky3/src/imports.rs b/codegen/plonky3/src/imports.rs index f0200360b..b7e6e81ec 100644 --- a/codegen/plonky3/src/imports.rs +++ b/codegen/plonky3/src/imports.rs @@ -6,6 +6,7 @@ pub(super) fn add_imports(scope: &mut Scope) { scope.import("p3_air", "Air"); scope.import("p3_air", "BaseAir"); scope.import("p3_air", "BaseAirWithPublicValues"); + scope.import("p3_air", "AirBuilder"); scope.import("p3_air", "ExtensionBuilder"); scope.import("p3_matrix", "Matrix"); scope.import("p3_field", "Field"); From 30e4b0727ad58cf005f36f0c9ea34637fef4906f Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 6 Nov 2025 14:41:43 +0100 Subject: [PATCH 06/22] tests: update winterfell E2E test following change --- air-script/tests/buses/buses_complex.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/air-script/tests/buses/buses_complex.rs b/air-script/tests/buses/buses_complex.rs index d15eeeb8f..33271a2ab 100644 --- a/air-script/tests/buses/buses_complex.rs +++ b/air-script/tests/buses/buses_complex.rs @@ -99,6 +99,6 @@ impl Air for BusesAir { let aux_current = aux_frame.current(); let aux_next = aux_frame.next(); result[0] = ((aux_rand_elements.rand_elements()[0] + aux_rand_elements.rand_elements()[1] + (E::from(Felt::new(3_u64)) + E::from(main_current[1])) * aux_rand_elements.rand_elements()[2] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[3]) * E::from(main_current[2]) + E::ONE - E::from(main_current[2])) * ((aux_rand_elements.rand_elements()[0] + E::from(Felt::new(2_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[1]) * aux_rand_elements.rand_elements()[2]) * (E::ONE - E::from(main_current[2])) + E::from(main_current[2])) * aux_current[0] - ((aux_rand_elements.rand_elements()[0] + aux_rand_elements.rand_elements()[1] + (E::from(Felt::new(3_u64)) + E::from(main_current[1])) * aux_rand_elements.rand_elements()[2] + E::from(main_current[1]) * aux_rand_elements.rand_elements()[3]) * E::from(main_current[3]) + E::ONE - E::from(main_current[3])) * ((aux_rand_elements.rand_elements()[0] + E::from(Felt::new(2_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (E::ONE - E::from(main_current[3])) + E::from(main_current[3])) * aux_next[0]; - result[1] = (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(4_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[1]) * aux_rand_elements.rand_elements()[2]) * aux_current[1] + (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(4_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[1]) * aux_rand_elements.rand_elements()[2]) * E::from(main_current[2]) + (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(4_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[1]) * aux_rand_elements.rand_elements()[2]) * E::from(main_current[2]) - ((aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(4_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[1]) * aux_rand_elements.rand_elements()[2]) * aux_next[1] + (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * E::from(main_current[4])); + result[1] = (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[1]) * aux_rand_elements.rand_elements()[2]) * aux_current[1] + (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[1]) * aux_rand_elements.rand_elements()[2]) * E::from(main_current[4]) + (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[1]) * aux_rand_elements.rand_elements()[2]) * E::from(main_current[5]) - ((aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[1]) * aux_rand_elements.rand_elements()[2]) * aux_next[1] + (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + E::from(Felt::new(3_u64)) * aux_rand_elements.rand_elements()[1] + E::from(main_current[0]) * aux_rand_elements.rand_elements()[2]) * E::from(main_current[6])); } } \ No newline at end of file From 0633eeb62715766941b33b74c9db7923a271312c Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 6 Nov 2025 14:45:40 +0100 Subject: [PATCH 07/22] chore: fix tests --- air-script/tests/buses/test_air_winterfell.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/air-script/tests/buses/test_air_winterfell.rs b/air-script/tests/buses/test_air_winterfell.rs index 7bf2ce5ea..a2e07196d 100644 --- a/air-script/tests/buses/test_air_winterfell.rs +++ b/air-script/tests/buses/test_air_winterfell.rs @@ -15,7 +15,7 @@ impl AirTester for BusesAirTester { type PubInputs = PublicInputs; fn build_main_trace(&self, length: usize) -> MyTraceTable { - let trace_width = 5; + let trace_width = 7; let start = Felt::new(0); let mut trace = TraceTable::new(trace_width, length); @@ -26,6 +26,8 @@ impl AirTester for BusesAirTester { state[2] = start; state[3] = start; state[4] = start; + state[5] = start; + state[6] = start; }, |_, state| { state[0] = Felt::new(1) - state[0]; @@ -33,6 +35,8 @@ impl AirTester for BusesAirTester { state[2] = Felt::new(1) - state[2]; state[3] = Felt::new(1) - state[3]; state[4] = Felt::new(1) - state[4]; + state[5] = Felt::new(1) - state[4]; + state[6] = Felt::new(1) - state[4]; }, ); From 1c8c54a76290dc327bb01d51a6561c03aed91246 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Wed, 12 Nov 2025 08:29:46 +0100 Subject: [PATCH 08/22] chore(tests): move air-script/tests codegen and helpers into src/test_utils module --- air-script/src/lib.rs | 5 + .../test_utils/air_tester_macros.rs} | 19 +- .../helpers.rs => src/test_utils/codegen.rs} | 2 +- air-script/src/test_utils/mod.rs | 9 + .../test_utils}/plonky3_traits.rs | 71 +--- .../test_utils/winterfell_traits.rs} | 0 air-script/{ => src}/tests/binary/binary.air | 0 air-script/{ => src}/tests/binary/binary.rs | 0 .../{ => src}/tests/binary/binary_plonky3.rs | 6 +- air-script/{ => src}/tests/binary/mod.rs | 0 .../tests/binary/test_air_plonky3.rs | 4 +- .../tests/binary/test_air_winterfell.rs | 6 +- .../{ => src}/tests/bitwise/bitwise.air | 0 air-script/{ => src}/tests/bitwise/bitwise.rs | 0 .../tests/bitwise/bitwise_plonky3.rs | 6 +- air-script/{ => src}/tests/bitwise/mod.rs | 0 .../tests/bitwise/test_air_plonky3.rs | 4 +- .../tests/bitwise/test_air_winterfell.rs | 6 +- .../{ => src}/tests/buses/buses_complex.air | 0 .../{ => src}/tests/buses/buses_complex.rs | 0 .../tests/buses/buses_complex_plonky3.rs | 2 +- .../{ => src}/tests/buses/buses_simple.air | 0 .../{ => src}/tests/buses/buses_simple.rs | 0 .../tests/buses/buses_simple_plonky3.rs | 6 +- .../buses/buses_simple_with_evaluators.air | 0 .../buses/buses_simple_with_evaluators.rs | 100 ++++++ .../buses_simple_with_evaluators_plonky3.rs | 76 ++++ .../buses/buses_varlen_boundary_both.air | 0 .../tests/buses/buses_varlen_boundary_both.rs | 0 .../buses_varlen_boundary_both_plonky3.rs | 6 +- .../buses/buses_varlen_boundary_first.air | 0 .../buses/buses_varlen_boundary_first.rs | 0 .../buses_varlen_boundary_first_plonky3.rs | 6 +- .../buses/buses_varlen_boundary_last.air | 0 .../tests/buses/buses_varlen_boundary_last.rs | 0 .../buses_varlen_boundary_last_plonky3.rs | 6 +- air-script/{ => src}/tests/buses/mod.rs | 0 .../{ => src}/tests/buses/test_air_plonky3.rs | 4 +- .../tests/buses/test_air_winterfell.rs | 6 +- .../computed_indices_complex.air | 0 .../computed_indices_complex.rs | 0 .../computed_indices_complex_plonky3.rs | 6 +- .../computed_indices_simple.air | 0 .../computed_indices_simple.rs | 0 .../computed_indices_simple_plonky3.rs | 6 +- air-script/src/tests/computed_indices/mod.rs | 18 + .../computed_indices/test_air_plonky3.rs | 73 ++++ .../computed_indices/test_air_winterfell.rs} | 25 +- .../constant_in_range/constant_in_range.air | 0 .../constant_in_range/constant_in_range.rs | 0 .../constant_in_range_module.air | 0 .../constant_in_range_plonky3.rs | 6 +- .../{ => src}/tests/constant_in_range/mod.rs | 0 .../constant_in_range/test_air_plonky3.rs | 4 +- .../constant_in_range/test_air_winterfell.rs | 6 +- .../{ => src}/tests/constants/constants.air | 0 .../{ => src}/tests/constants/constants.rs | 0 .../tests/constants/constants_plonky3.rs | 6 +- air-script/{ => src}/tests/constants/mod.rs | 0 .../tests/constants/test_air_plonky3.rs | 4 +- .../tests/constants/test_air_winterfell.rs | 6 +- .../cc_with_evaluators.air | 0 .../constraint_comprehension.air | 0 .../constraint_comprehension.rs | 0 .../constraint_comprehension_plonky3.rs | 6 +- .../tests/constraint_comprehension/mod.rs | 0 .../test_air_plonky3.rs | 6 +- .../test_air_winterfell.rs | 6 +- air-script/{ => src}/tests/docs_sync.rs | 0 .../{ => src}/tests/evaluators/evaluators.air | 0 .../{ => src}/tests/evaluators/evaluators.rs | 0 .../tests/evaluators/evaluators_plonky3.rs | 6 +- air-script/{ => src}/tests/evaluators/mod.rs | 0 .../tests/evaluators/test_air_plonky3.rs | 4 +- .../tests/evaluators/test_air_winterfell.rs | 6 +- .../{ => src}/tests/fibonacci/fibonacci.air | 0 .../{ => src}/tests/fibonacci/fibonacci.rs | 0 .../tests/fibonacci/fibonacci_plonky3.rs | 6 +- air-script/{ => src}/tests/fibonacci/mod.rs | 0 .../tests/fibonacci/test_air_plonky3.rs | 4 +- .../tests/fibonacci/test_air_winterfell.rs | 6 +- .../tests/functions/functions_complex.air | 0 .../tests/functions/functions_complex.rs | 0 .../functions/functions_complex_plonky3.rs | 6 +- .../tests/functions/functions_simple.air | 0 .../tests/functions/functions_simple.rs | 0 .../functions/functions_simple_plonky3.rs | 6 +- .../functions/inlined_functions_simple.air | 0 air-script/{ => src}/tests/functions/mod.rs | 0 .../tests/functions/test_air_plonky3.rs | 4 +- .../tests/functions/test_air_winterfell.rs | 6 +- .../indexed_trace_access.air | 0 .../indexed_trace_access.rs | 0 .../indexed_trace_access_plonky3.rs | 6 +- .../tests/indexed_trace_access/mod.rs | 0 .../indexed_trace_access/test_air_plonky3.rs | 4 +- .../test_air_winterfell.rs | 6 +- .../list_comprehension/list_comprehension.air | 0 .../list_comprehension/list_comprehension.rs | 0 .../list_comprehension_nested.air | 0 .../list_comprehension_nested.rs | 0 .../list_comprehension_nested_plonky3.rs | 6 +- .../list_comprehension_plonky3.rs | 6 +- .../{ => src}/tests/list_comprehension/mod.rs | 0 .../list_comprehension/test_air_plonky3.rs | 4 +- .../list_comprehension/test_air_winterfell.rs | 6 +- .../tests/list_folding/list_folding.air | 0 .../tests/list_folding/list_folding.rs | 0 .../list_folding/list_folding_plonky3.rs | 6 +- .../{ => src}/tests/list_folding/mod.rs | 0 .../tests/list_folding/test_air_plonky3.rs | 4 +- .../tests/list_folding/test_air_winterfell.rs | 6 +- air-script/{ => src}/tests/mod.rs | 6 +- .../{ => src}/tests/periodic_columns/mod.rs | 0 .../periodic_columns/periodic_columns.air | 0 .../periodic_columns/periodic_columns.rs | 0 .../periodic_columns_plonky3.rs | 6 +- .../periodic_columns/test_air_plonky3.rs | 4 +- .../periodic_columns/test_air_winterfell.rs | 6 +- air-script/src/tests/plonky3.rs | 333 +++++++++++++++++ air-script/{ => src}/tests/pub_inputs/mod.rs | 0 .../{ => src}/tests/pub_inputs/pub_inputs.air | 0 .../{ => src}/tests/pub_inputs/pub_inputs.rs | 0 .../tests/pub_inputs/pub_inputs_plonky3.rs | 6 +- .../tests/pub_inputs/test_air_plonky3.rs | 4 +- .../tests/pub_inputs/test_air_winterfell.rs | 6 +- air-script/{ => src}/tests/selectors/mod.rs | 0 .../{ => src}/tests/selectors/selectors.air | 0 .../{ => src}/tests/selectors/selectors.rs | 0 .../selectors/selectors_combine_complex.air | 0 .../selectors/selectors_combine_complex.rs | 0 .../selectors_combine_complex_plonky3.rs | 2 +- .../selectors/selectors_combine_simple.air | 0 .../selectors/selectors_combine_simple.rs | 0 .../selectors_combine_simple_plonky3.rs | 6 +- ...ctors_combine_with_list_comprehensions.air | 0 ...ectors_combine_with_list_comprehensions.rs | 0 ...ombine_with_list_comprehensions_plonky3.rs | 6 +- .../tests/selectors/selectors_plonky3.rs | 6 +- .../selectors/selectors_with_evaluators.air | 0 .../selectors/selectors_with_evaluators.rs | 0 .../selectors_with_evaluators_plonky3.rs | 6 +- .../tests/selectors/test_air_plonky3.rs | 4 +- .../tests/selectors/test_air_winterfell.rs | 6 +- air-script/{ => src}/tests/system/mod.rs | 0 air-script/{ => src}/tests/system/system.air | 0 air-script/{ => src}/tests/system/system.rs | 0 .../{ => src}/tests/system/system_plonky3.rs | 6 +- .../tests/system/test_air_plonky3.rs | 4 +- .../tests/system/test_air_winterfell.rs | 6 +- .../{ => src}/tests/trace_col_groups/mod.rs | 0 .../trace_col_groups/test_air_plonky3.rs | 4 +- .../trace_col_groups/test_air_winterfell.rs | 6 +- .../trace_col_groups/trace_col_groups.air | 0 .../trace_col_groups/trace_col_groups.rs | 0 .../trace_col_groups_plonky3.rs | 6 +- air-script/{ => src}/tests/variables/mod.rs | 0 .../tests/variables/test_air_plonky3.rs | 4 +- .../tests/variables/test_air_winterfell.rs | 6 +- .../{ => src}/tests/variables/variables.air | 0 .../{ => src}/tests/variables/variables.rs | 0 .../tests/variables/variables_plonky3.rs | 6 +- air-script/src/tests/winterfell.rs | 335 ++++++++++++++++++ air-script/tests/codegen/mod.rs | 3 - air-script/tests/codegen/plonky3.rs | 323 ----------------- air-script/tests/codegen/winterfell.rs | 335 ------------------ air-script/tests/computed_indices/mod.rs | 7 - air-script/tests/helpers/mod.rs | 11 - .../tests/helpers/plonky3_periodic_columns.rs | 146 -------- codegen/plonky3/src/imports.rs | 4 +- 170 files changed, 1213 insertions(+), 1042 deletions(-) rename air-script/{tests/helpers/macros.rs => src/test_utils/air_tester_macros.rs} (79%) rename air-script/{tests/codegen/helpers.rs => src/test_utils/codegen.rs} (99%) create mode 100644 air-script/src/test_utils/mod.rs rename air-script/{tests/helpers => src/test_utils}/plonky3_traits.rs (80%) rename air-script/{tests/helpers/winterfell_test_helpers.rs => src/test_utils/winterfell_traits.rs} (100%) rename air-script/{ => src}/tests/binary/binary.air (100%) rename air-script/{ => src}/tests/binary/binary.rs (100%) rename air-script/{ => src}/tests/binary/binary_plonky3.rs (92%) rename air-script/{ => src}/tests/binary/mod.rs (100%) rename air-script/{ => src}/tests/binary/test_air_plonky3.rs (92%) rename air-script/{ => src}/tests/binary/test_air_winterfell.rs (87%) rename air-script/{ => src}/tests/bitwise/bitwise.air (100%) rename air-script/{ => src}/tests/bitwise/bitwise.rs (100%) rename air-script/{ => src}/tests/bitwise/bitwise_plonky3.rs (97%) rename air-script/{ => src}/tests/bitwise/mod.rs (100%) rename air-script/{ => src}/tests/bitwise/test_air_plonky3.rs (95%) rename air-script/{ => src}/tests/bitwise/test_air_winterfell.rs (90%) rename air-script/{ => src}/tests/buses/buses_complex.air (100%) rename air-script/{ => src}/tests/buses/buses_complex.rs (100%) rename air-script/{ => src}/tests/buses/buses_complex_plonky3.rs (98%) rename air-script/{ => src}/tests/buses/buses_simple.air (100%) rename air-script/{ => src}/tests/buses/buses_simple.rs (100%) rename air-script/{ => src}/tests/buses/buses_simple_plonky3.rs (95%) rename air-script/{ => src}/tests/buses/buses_simple_with_evaluators.air (100%) create mode 100644 air-script/src/tests/buses/buses_simple_with_evaluators.rs create mode 100644 air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs rename air-script/{ => src}/tests/buses/buses_varlen_boundary_both.air (100%) rename air-script/{ => src}/tests/buses/buses_varlen_boundary_both.rs (100%) rename air-script/{ => src}/tests/buses/buses_varlen_boundary_both_plonky3.rs (96%) rename air-script/{ => src}/tests/buses/buses_varlen_boundary_first.air (100%) rename air-script/{ => src}/tests/buses/buses_varlen_boundary_first.rs (100%) rename air-script/{ => src}/tests/buses/buses_varlen_boundary_first_plonky3.rs (96%) rename air-script/{ => src}/tests/buses/buses_varlen_boundary_last.air (100%) rename air-script/{ => src}/tests/buses/buses_varlen_boundary_last.rs (100%) rename air-script/{ => src}/tests/buses/buses_varlen_boundary_last_plonky3.rs (96%) rename air-script/{ => src}/tests/buses/mod.rs (100%) rename air-script/{ => src}/tests/buses/test_air_plonky3.rs (94%) rename air-script/{ => src}/tests/buses/test_air_winterfell.rs (92%) rename air-script/{ => src}/tests/computed_indices/computed_indices_complex.air (100%) rename air-script/{ => src}/tests/computed_indices/computed_indices_complex.rs (100%) rename air-script/{ => src}/tests/computed_indices/computed_indices_complex_plonky3.rs (92%) rename air-script/{ => src}/tests/computed_indices/computed_indices_simple.air (100%) rename air-script/{ => src}/tests/computed_indices/computed_indices_simple.rs (100%) rename air-script/{ => src}/tests/computed_indices/computed_indices_simple_plonky3.rs (94%) create mode 100644 air-script/src/tests/computed_indices/mod.rs create mode 100644 air-script/src/tests/computed_indices/test_air_plonky3.rs rename air-script/{tests/computed_indices/test_air.rs => src/tests/computed_indices/test_air_winterfell.rs} (63%) rename air-script/{ => src}/tests/constant_in_range/constant_in_range.air (100%) rename air-script/{ => src}/tests/constant_in_range/constant_in_range.rs (100%) rename air-script/{ => src}/tests/constant_in_range/constant_in_range_module.air (100%) rename air-script/{ => src}/tests/constant_in_range/constant_in_range_plonky3.rs (93%) rename air-script/{ => src}/tests/constant_in_range/mod.rs (100%) rename air-script/{ => src}/tests/constant_in_range/test_air_plonky3.rs (93%) rename air-script/{ => src}/tests/constant_in_range/test_air_winterfell.rs (86%) rename air-script/{ => src}/tests/constants/constants.air (100%) rename air-script/{ => src}/tests/constants/constants.rs (100%) rename air-script/{ => src}/tests/constants/constants_plonky3.rs (94%) rename air-script/{ => src}/tests/constants/mod.rs (100%) rename air-script/{ => src}/tests/constants/test_air_plonky3.rs (93%) rename air-script/{ => src}/tests/constants/test_air_winterfell.rs (88%) rename air-script/{ => src}/tests/constraint_comprehension/cc_with_evaluators.air (100%) rename air-script/{ => src}/tests/constraint_comprehension/constraint_comprehension.air (100%) rename air-script/{ => src}/tests/constraint_comprehension/constraint_comprehension.rs (100%) rename air-script/{ => src}/tests/constraint_comprehension/constraint_comprehension_plonky3.rs (93%) rename air-script/{ => src}/tests/constraint_comprehension/mod.rs (100%) rename air-script/{ => src}/tests/constraint_comprehension/test_air_plonky3.rs (92%) rename air-script/{ => src}/tests/constraint_comprehension/test_air_winterfell.rs (85%) rename air-script/{ => src}/tests/docs_sync.rs (100%) rename air-script/{ => src}/tests/evaluators/evaluators.air (100%) rename air-script/{ => src}/tests/evaluators/evaluators.rs (100%) rename air-script/{ => src}/tests/evaluators/evaluators_plonky3.rs (94%) rename air-script/{ => src}/tests/evaluators/mod.rs (100%) rename air-script/{ => src}/tests/evaluators/test_air_plonky3.rs (93%) rename air-script/{ => src}/tests/evaluators/test_air_winterfell.rs (86%) rename air-script/{ => src}/tests/fibonacci/fibonacci.air (100%) rename air-script/{ => src}/tests/fibonacci/fibonacci.rs (100%) rename air-script/{ => src}/tests/fibonacci/fibonacci_plonky3.rs (93%) rename air-script/{ => src}/tests/fibonacci/mod.rs (100%) rename air-script/{ => src}/tests/fibonacci/test_air_plonky3.rs (92%) rename air-script/{ => src}/tests/fibonacci/test_air_winterfell.rs (88%) rename air-script/{ => src}/tests/functions/functions_complex.air (100%) rename air-script/{ => src}/tests/functions/functions_complex.rs (100%) rename air-script/{ => src}/tests/functions/functions_complex_plonky3.rs (95%) rename air-script/{ => src}/tests/functions/functions_simple.air (100%) rename air-script/{ => src}/tests/functions/functions_simple.rs (100%) rename air-script/{ => src}/tests/functions/functions_simple_plonky3.rs (95%) rename air-script/{ => src}/tests/functions/inlined_functions_simple.air (100%) rename air-script/{ => src}/tests/functions/mod.rs (100%) rename air-script/{ => src}/tests/functions/test_air_plonky3.rs (95%) rename air-script/{ => src}/tests/functions/test_air_winterfell.rs (92%) rename air-script/{ => src}/tests/indexed_trace_access/indexed_trace_access.air (100%) rename air-script/{ => src}/tests/indexed_trace_access/indexed_trace_access.rs (100%) rename air-script/{ => src}/tests/indexed_trace_access/indexed_trace_access_plonky3.rs (92%) rename air-script/{ => src}/tests/indexed_trace_access/mod.rs (100%) rename air-script/{ => src}/tests/indexed_trace_access/test_air_plonky3.rs (90%) rename air-script/{ => src}/tests/indexed_trace_access/test_air_winterfell.rs (83%) rename air-script/{ => src}/tests/list_comprehension/list_comprehension.air (100%) rename air-script/{ => src}/tests/list_comprehension/list_comprehension.rs (100%) rename air-script/{ => src}/tests/list_comprehension/list_comprehension_nested.air (100%) rename air-script/{ => src}/tests/list_comprehension/list_comprehension_nested.rs (100%) rename air-script/{ => src}/tests/list_comprehension/list_comprehension_nested_plonky3.rs (93%) rename air-script/{ => src}/tests/list_comprehension/list_comprehension_plonky3.rs (94%) rename air-script/{ => src}/tests/list_comprehension/mod.rs (100%) rename air-script/{ => src}/tests/list_comprehension/test_air_plonky3.rs (94%) rename air-script/{ => src}/tests/list_comprehension/test_air_winterfell.rs (87%) rename air-script/{ => src}/tests/list_folding/list_folding.air (100%) rename air-script/{ => src}/tests/list_folding/list_folding.rs (100%) rename air-script/{ => src}/tests/list_folding/list_folding_plonky3.rs (95%) rename air-script/{ => src}/tests/list_folding/mod.rs (100%) rename air-script/{ => src}/tests/list_folding/test_air_plonky3.rs (95%) rename air-script/{ => src}/tests/list_folding/test_air_winterfell.rs (89%) rename air-script/{ => src}/tests/mod.rs (97%) rename air-script/{ => src}/tests/periodic_columns/mod.rs (100%) rename air-script/{ => src}/tests/periodic_columns/periodic_columns.air (100%) rename air-script/{ => src}/tests/periodic_columns/periodic_columns.rs (100%) rename air-script/{ => src}/tests/periodic_columns/periodic_columns_plonky3.rs (93%) rename air-script/{ => src}/tests/periodic_columns/test_air_plonky3.rs (91%) rename air-script/{ => src}/tests/periodic_columns/test_air_winterfell.rs (82%) create mode 100644 air-script/src/tests/plonky3.rs rename air-script/{ => src}/tests/pub_inputs/mod.rs (100%) rename air-script/{ => src}/tests/pub_inputs/pub_inputs.air (100%) rename air-script/{ => src}/tests/pub_inputs/pub_inputs.rs (100%) rename air-script/{ => src}/tests/pub_inputs/pub_inputs_plonky3.rs (94%) rename air-script/{ => src}/tests/pub_inputs/test_air_plonky3.rs (92%) rename air-script/{ => src}/tests/pub_inputs/test_air_winterfell.rs (85%) rename air-script/{ => src}/tests/selectors/mod.rs (100%) rename air-script/{ => src}/tests/selectors/selectors.air (100%) rename air-script/{ => src}/tests/selectors/selectors.rs (100%) rename air-script/{ => src}/tests/selectors/selectors_combine_complex.air (100%) rename air-script/{ => src}/tests/selectors/selectors_combine_complex.rs (100%) rename air-script/{ => src}/tests/selectors/selectors_combine_complex_plonky3.rs (98%) rename air-script/{ => src}/tests/selectors/selectors_combine_simple.air (100%) rename air-script/{ => src}/tests/selectors/selectors_combine_simple.rs (100%) rename air-script/{ => src}/tests/selectors/selectors_combine_simple_plonky3.rs (93%) rename air-script/{ => src}/tests/selectors/selectors_combine_with_list_comprehensions.air (100%) rename air-script/{ => src}/tests/selectors/selectors_combine_with_list_comprehensions.rs (100%) rename air-script/{ => src}/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs (94%) rename air-script/{ => src}/tests/selectors/selectors_plonky3.rs (93%) rename air-script/{ => src}/tests/selectors/selectors_with_evaluators.air (100%) rename air-script/{ => src}/tests/selectors/selectors_with_evaluators.rs (100%) rename air-script/{ => src}/tests/selectors/selectors_with_evaluators_plonky3.rs (93%) rename air-script/{ => src}/tests/selectors/test_air_plonky3.rs (92%) rename air-script/{ => src}/tests/selectors/test_air_winterfell.rs (84%) rename air-script/{ => src}/tests/system/mod.rs (100%) rename air-script/{ => src}/tests/system/system.air (100%) rename air-script/{ => src}/tests/system/system.rs (100%) rename air-script/{ => src}/tests/system/system_plonky3.rs (92%) rename air-script/{ => src}/tests/system/test_air_plonky3.rs (92%) rename air-script/{ => src}/tests/system/test_air_winterfell.rs (86%) rename air-script/{ => src}/tests/trace_col_groups/mod.rs (100%) rename air-script/{ => src}/tests/trace_col_groups/test_air_plonky3.rs (93%) rename air-script/{ => src}/tests/trace_col_groups/test_air_winterfell.rs (86%) rename air-script/{ => src}/tests/trace_col_groups/trace_col_groups.air (100%) rename air-script/{ => src}/tests/trace_col_groups/trace_col_groups.rs (100%) rename air-script/{ => src}/tests/trace_col_groups/trace_col_groups_plonky3.rs (92%) rename air-script/{ => src}/tests/variables/mod.rs (100%) rename air-script/{ => src}/tests/variables/test_air_plonky3.rs (92%) rename air-script/{ => src}/tests/variables/test_air_winterfell.rs (86%) rename air-script/{ => src}/tests/variables/variables.air (100%) rename air-script/{ => src}/tests/variables/variables.rs (100%) rename air-script/{ => src}/tests/variables/variables_plonky3.rs (94%) create mode 100644 air-script/src/tests/winterfell.rs delete mode 100644 air-script/tests/codegen/mod.rs delete mode 100644 air-script/tests/codegen/plonky3.rs delete mode 100644 air-script/tests/codegen/winterfell.rs delete mode 100644 air-script/tests/computed_indices/mod.rs delete mode 100644 air-script/tests/helpers/mod.rs delete mode 100644 air-script/tests/helpers/plonky3_periodic_columns.rs diff --git a/air-script/src/lib.rs b/air-script/src/lib.rs index 5d477c7d0..67c255f21 100644 --- a/air-script/src/lib.rs +++ b/air-script/src/lib.rs @@ -1,3 +1,8 @@ pub use air_codegen_winter::CodeGenerator as WinterfellCodeGenerator; pub use air_ir::{Air, CompileError, compile}; pub use air_parser::{parse, parse_file, transforms}; + +#[cfg(test)] +pub mod test_utils; +#[cfg(test)] +mod tests; diff --git a/air-script/tests/helpers/macros.rs b/air-script/src/test_utils/air_tester_macros.rs similarity index 79% rename from air-script/tests/helpers/macros.rs rename to air-script/src/test_utils/air_tester_macros.rs index 6f9586249..f2352b243 100644 --- a/air-script/tests/helpers/macros.rs +++ b/air-script/src/test_utils/air_tester_macros.rs @@ -36,12 +36,12 @@ macro_rules! generate_air_winterfell_test { /// * `test_name` - The identifier for the test function (e.g., `test_binary_air`) /// * `air_name` - The identifier for the AIR struct (e.g., `BinaryAir`) #[macro_export] -macro_rules! generate_air_plonky3_test { +macro_rules! generate_air_plonky3_test_with_airscript_traits { ($test_name:ident, $air_name:ident) => { #[test] fn $test_name() { type Val = Goldilocks; - type Challenge = BinomialExtensionField; + type Challenge = BinomialExtensionField; type ByteHash = Sha256; type FieldHash = SerializingHasher; @@ -67,18 +67,15 @@ macro_rules! generate_air_plonky3_test { let config = MyConfig::new(pcs, challenger); let inputs = generate_inputs(); - let inputs_goldilocks: Vec = - inputs.iter().map(|&x| Val::from_u32(x)).collect(); + let inputs_goldilocks: Vec = inputs.iter().map(|&x| Val::from_u32(x)).collect(); let trace = generate_trace_rows::(inputs); - check_constraints_with_periodic_columns(&$air_name {}, &trace, &inputs_goldilocks); - - /*let prove_with_periodic_columns = prove_with_periodic_columns(&config, &BitwiseAir {}, trace, &inputs_goldilocks); - verify_with_periodic_columns(&config, &BitwiseAir {}, &prove_with_periodic_columns, &inputs_goldilocks).expect("Verification failed");*/ - - /*let proof = prove(&config, &BitwiseAir {}, trace, &inputs_goldilocks); - verify(&config, &BitwiseAir {}, &proof, &inputs_goldilocks).expect("Verification failed");*/ + check_constraints_with_airscript_traits::( + &$air_name {}, + &trace, + &inputs_goldilocks, + ); } }; } diff --git a/air-script/tests/codegen/helpers.rs b/air-script/src/test_utils/codegen.rs similarity index 99% rename from air-script/tests/codegen/helpers.rs rename to air-script/src/test_utils/codegen.rs index 577144d42..5dbcbba8d 100644 --- a/air-script/tests/codegen/helpers.rs +++ b/air-script/src/test_utils/codegen.rs @@ -1,7 +1,7 @@ use std::sync::Arc; +use crate::compile; use air_ir::{CodeGenerator, CompileError}; -use air_script::compile; use miden_diagnostics::{ CodeMap, DefaultEmitter, DiagnosticsHandler, term::termcolor::ColorChoice, }; diff --git a/air-script/src/test_utils/mod.rs b/air-script/src/test_utils/mod.rs new file mode 100644 index 000000000..91742998c --- /dev/null +++ b/air-script/src/test_utils/mod.rs @@ -0,0 +1,9 @@ + +/// Macros to generate Air tester structs and tests for both Plonky3 and Winterfell backends. +pub mod air_tester_macros; +/// Code generation for tests/**/*.air files. +pub mod codegen; +/// Plonky3-specific traits, to be moved to 0xMiden/Plonky3 once stabilized. +pub mod plonky3_traits; +/// Winterfell-specific traits +pub mod winterfell_traits; diff --git a/air-script/tests/helpers/plonky3_traits.rs b/air-script/src/test_utils/plonky3_traits.rs similarity index 80% rename from air-script/tests/helpers/plonky3_traits.rs rename to air-script/src/test_utils/plonky3_traits.rs index a9da6a736..644685224 100644 --- a/air-script/tests/helpers/plonky3_traits.rs +++ b/air-script/src/test_utils/plonky3_traits.rs @@ -21,7 +21,6 @@ pub trait AirScriptAir> { } /// Periodic constants (base-field) backing periodic_evals(). - // fn periodic_table(&self) -> &'static [&'static [F]]; fn periodic_table(&self) -> Vec>; /// Single entrypoint: encodes main + aux + boundary constraints. @@ -47,61 +46,6 @@ where fn aux_bus_boundary_values(&self) -> &[::VarEF]; } -// Helper macros for Plonky3 test generation - -/// Generates a Plonky3 AIR test function with the standard boilerplate -/// -/// # Arguments -/// * `test_name` - The identifier for the test function (e.g., `test_binary_air`) -/// * `air_name` - The identifier for the AIR struct (e.g., `BinaryAir`) -#[macro_export] -macro_rules! generate_air_plonky3_test_with_airscript_traits { - ($test_name:ident, $air_name:ident) => { - #[test] - fn $test_name() { - type Val = Goldilocks; - type Challenge = BinomialExtensionField; - - type ByteHash = Sha256; - type FieldHash = SerializingHasher; - type MyCompress = CompressionFunctionFromHasher; - type ValMmcs = MerkleTreeMmcs; - type ChallengeMmcs = ExtensionMmcs; - type Challenger = SerializingChallenger64>; - type Pcs = CirclePcs; - type MyConfig = StarkConfig; - - let byte_hash = ByteHash {}; - let field_hash = FieldHash::new(Sha256); - let compress = MyCompress::new(byte_hash); - let val_mmcs = ValMmcs::new(field_hash, compress); - let challenge_mmcs = ChallengeMmcs::new(val_mmcs.clone()); - let challenger = Challenger::from_hasher(vec![], byte_hash); - let fri_params = create_benchmark_fri_params(challenge_mmcs); - let pcs = Pcs { - mmcs: val_mmcs, - fri_params, - _phantom: PhantomData, - }; - let config = MyConfig::new(pcs, challenger); - - let inputs = generate_inputs(); - let inputs_goldilocks: Vec = - inputs.iter().map(|&x| Val::from_u32(x)).collect(); - - let trace = generate_trace_rows::(inputs); - - check_constraints_with_airscript_traits::(&$air_name {}, &trace, &inputs_goldilocks); - - /*let prove_with_periodic_columns = prove_with_periodic_columns(&config, &BitwiseAir {}, trace, &inputs_goldilocks); - verify_with_periodic_columns(&config, &BitwiseAir {}, &prove_with_periodic_columns, &inputs_goldilocks).expect("Verification failed");*/ - - /*let proof = prove(&config, &BitwiseAir {}, trace, &inputs_goldilocks); - verify(&config, &BitwiseAir {}, &proof, &inputs_goldilocks).expect("Verification failed");*/ - } - }; -} - /// A builder that runs constraint assertions during testing. /// /// Used in conjunction with [`check_constraints`] to simulate @@ -110,8 +54,10 @@ macro_rules! generate_air_plonky3_test_with_airscript_traits { pub struct DebugConstraintBuilderWithAirScriptTraits<'a, F: Field, EF: ExtensionField> { /// The index of the row currently being evaluated. row_index: usize, - /// A view of the current and next row as a vertical pair. + /// A view of the current and next main row as a vertical pair. main: VerticalPair, RowMajorMatrixView<'a, F>>, + /// A view of the current and next aux row as a vertical pair. + aux: VerticalPair, RowMajorMatrixView<'a, EF>>, /// The public values provided for constraint validation (e.g. inputs or outputs). public_values: &'a [F], /// A flag indicating whether this is the first row. @@ -130,8 +76,6 @@ pub struct DebugConstraintBuilderWithAirScriptTraits<'a, F: Field, EF: Extension beta: EF, /// The aux bus boundary values in the extension field. aux_bus_boundary_values: Vec, - /// The aux trace as a vertical pair. - permutation: VerticalPair, RowMajorMatrixView<'a, EF>>, } impl<'a, F, EF> AirBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> @@ -223,7 +167,7 @@ where type RandomVar = EF; fn permutation(&self) -> Self::MP { - self.permutation + self.aux } fn permutation_randomness(&self) -> &[Self::RandomVar] { @@ -360,7 +304,8 @@ pub(crate) fn check_constraints_with_airscript_traits( let height = main.height(); let aux_bus_boundary_values: Vec<_> = (0..air.aux_width()).map(|_| EF::GENERATOR).collect(); - let alpha = EF::from_u64(123456789); + let alpha_f: Vec = (0..5).map(|i| F::from_u64(123456789 * i)).collect(); // Dummy alpha in F + let alpha = EF::from_basis_coefficients_iter(alpha_f.iter().cloned()).unwrap(); let beta = EF::from_u64(987654321); let alpha_powers: Vec = (0..air.num_alpha_challenges()) .map(|power| alpha.exp_u64(power as u64)) @@ -396,9 +341,12 @@ pub(crate) fn check_constraints_with_airscript_traits( RowMajorMatrixView::new_row(&aux_next), ); + println!("Evaluating aux current row {}: {:?}", i, aux_local); + let mut builder = DebugConstraintBuilderWithAirScriptTraits { row_index: i, main, + aux, public_values, is_first_row: F::from_bool(i == 0), is_last_row: F::from_bool(i == height - 1), @@ -408,7 +356,6 @@ pub(crate) fn check_constraints_with_airscript_traits( beta, alpha_powers: alpha_powers.clone(), aux_bus_boundary_values: aux_bus_boundary_values.clone(), - permutation: aux, }; AirScriptAir::eval(air, &mut builder); diff --git a/air-script/tests/helpers/winterfell_test_helpers.rs b/air-script/src/test_utils/winterfell_traits.rs similarity index 100% rename from air-script/tests/helpers/winterfell_test_helpers.rs rename to air-script/src/test_utils/winterfell_traits.rs diff --git a/air-script/tests/binary/binary.air b/air-script/src/tests/binary/binary.air similarity index 100% rename from air-script/tests/binary/binary.air rename to air-script/src/tests/binary/binary.air diff --git a/air-script/tests/binary/binary.rs b/air-script/src/tests/binary/binary.rs similarity index 100% rename from air-script/tests/binary/binary.rs rename to air-script/src/tests/binary/binary.rs diff --git a/air-script/tests/binary/binary_plonky3.rs b/air-script/src/tests/binary/binary_plonky3.rs similarity index 92% rename from air-script/tests/binary/binary_plonky3.rs rename to air-script/src/tests/binary/binary_plonky3.rs index 2dad894a8..d9f4dc26d 100644 --- a/air-script/tests/binary/binary_plonky3.rs +++ b/air-script/src/tests/binary/binary_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 2; pub const AUX_WIDTH: usize = 0; @@ -52,6 +52,10 @@ impl> AirScriptAir for BinaryAir { // Main integrity/transition constraints builder.assert_zero(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); builder.assert_zero(main_current[1].clone().into() * main_current[1].clone().into() - main_current[1].clone().into()); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/binary/mod.rs b/air-script/src/tests/binary/mod.rs similarity index 100% rename from air-script/tests/binary/mod.rs rename to air-script/src/tests/binary/mod.rs diff --git a/air-script/tests/binary/test_air_plonky3.rs b/air-script/src/tests/binary/test_air_plonky3.rs similarity index 92% rename from air-script/tests/binary/test_air_plonky3.rs rename to air-script/src/tests/binary/test_air_plonky3.rs index efca75dcf..c60b72a0c 100644 --- a/air-script/tests/binary/test_air_plonky3.rs +++ b/air-script/src/tests/binary/test_air_plonky3.rs @@ -13,9 +13,9 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - binary::binary_plonky3::{BinaryAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::binary::binary_plonky3::{BinaryAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/binary/test_air_winterfell.rs b/air-script/src/tests/binary/test_air_winterfell.rs similarity index 87% rename from air-script/tests/binary/test_air_winterfell.rs rename to air-script/src/tests/binary/test_air_winterfell.rs index eca996b11..2135c11b6 100644 --- a/air-script/tests/binary/test_air_winterfell.rs +++ b/air-script/src/tests/binary/test_air_winterfell.rs @@ -3,9 +3,9 @@ use winter_math::fields::f64::BaseElement as Felt; use winterfell::{Trace, TraceTable}; use crate::{ - binary::binary::PublicInputs, generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::binary::binary::PublicInputs, }; #[derive(Clone)] @@ -41,7 +41,7 @@ impl AirTester for BinaryAirTester { generate_air_winterfell_test!( test_binary_air, - crate::binary::binary::BinaryAir, + crate::tests::binary::binary::BinaryAir, BinaryAirTester, 1024 ); diff --git a/air-script/tests/bitwise/bitwise.air b/air-script/src/tests/bitwise/bitwise.air similarity index 100% rename from air-script/tests/bitwise/bitwise.air rename to air-script/src/tests/bitwise/bitwise.air diff --git a/air-script/tests/bitwise/bitwise.rs b/air-script/src/tests/bitwise/bitwise.rs similarity index 100% rename from air-script/tests/bitwise/bitwise.rs rename to air-script/src/tests/bitwise/bitwise.rs diff --git a/air-script/tests/bitwise/bitwise_plonky3.rs b/air-script/src/tests/bitwise/bitwise_plonky3.rs similarity index 97% rename from air-script/tests/bitwise/bitwise_plonky3.rs rename to air-script/src/tests/bitwise/bitwise_plonky3.rs index 86b847eec..be2ed40ae 100644 --- a/air-script/tests/bitwise/bitwise_plonky3.rs +++ b/air-script/src/tests/bitwise/bitwise_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 14; pub const AUX_WIDTH: usize = 0; @@ -70,6 +70,10 @@ impl> AirScriptAir for BitwiseAir { builder.assert_zero_ext(periodic_values[0].into() * AB::ExprEF::from(main_current[11].clone().into())); builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_current[12].clone().into()) - AB::ExprEF::from(main_next[11].clone().into()))); builder.assert_zero((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() * main_current[7].clone().into() + main_current[4].clone().into().double() * main_current[8].clone().into() + AB::Expr::from_u64(4) * main_current[5].clone().into() * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into() * main_current[10].clone().into())) + main_current[0].clone().into() * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[7].clone().into() - main_current[3].clone().into().double() * main_current[7].clone().into() + (main_current[4].clone().into() + main_current[8].clone().into() - main_current[4].clone().into().double() * main_current[8].clone().into()).double() + AB::Expr::from_u64(4) * (main_current[5].clone().into() + main_current[9].clone().into() - main_current[5].clone().into().double() * main_current[9].clone().into()) + AB::Expr::from_u64(8) * (main_current[6].clone().into() + main_current[10].clone().into() - main_current[6].clone().into().double() * main_current[10].clone().into())))); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/bitwise/mod.rs b/air-script/src/tests/bitwise/mod.rs similarity index 100% rename from air-script/tests/bitwise/mod.rs rename to air-script/src/tests/bitwise/mod.rs diff --git a/air-script/tests/bitwise/test_air_plonky3.rs b/air-script/src/tests/bitwise/test_air_plonky3.rs similarity index 95% rename from air-script/tests/bitwise/test_air_plonky3.rs rename to air-script/src/tests/bitwise/test_air_plonky3.rs index d88fa475a..87e297ff7 100644 --- a/air-script/tests/bitwise/test_air_plonky3.rs +++ b/air-script/src/tests/bitwise/test_air_plonky3.rs @@ -13,9 +13,9 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - bitwise::bitwise_plonky3::{BitwiseAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::bitwise::bitwise_plonky3::{BitwiseAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/bitwise/test_air_winterfell.rs b/air-script/src/tests/bitwise/test_air_winterfell.rs similarity index 90% rename from air-script/tests/bitwise/test_air_winterfell.rs rename to air-script/src/tests/bitwise/test_air_winterfell.rs index c5166f091..e563782ef 100644 --- a/air-script/tests/bitwise/test_air_winterfell.rs +++ b/air-script/src/tests/bitwise/test_air_winterfell.rs @@ -5,9 +5,9 @@ use winter_math::fields::f64::BaseElement as Felt; use winterfell::{AuxTraceWithMetadata, Trace, TraceTable, matrix::ColMatrix}; use crate::{ - bitwise::bitwise::PublicInputs, generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::bitwise::bitwise::PublicInputs, }; #[derive(Clone)] @@ -52,7 +52,7 @@ impl AirTester for BitwiseAirTester { generate_air_winterfell_test!( test_bitwise_air, - crate::bitwise::bitwise::BitwiseAir, + crate::tests::bitwise::bitwise::BitwiseAir, BitwiseAirTester, 1024 ); diff --git a/air-script/tests/buses/buses_complex.air b/air-script/src/tests/buses/buses_complex.air similarity index 100% rename from air-script/tests/buses/buses_complex.air rename to air-script/src/tests/buses/buses_complex.air diff --git a/air-script/tests/buses/buses_complex.rs b/air-script/src/tests/buses/buses_complex.rs similarity index 100% rename from air-script/tests/buses/buses_complex.rs rename to air-script/src/tests/buses/buses_complex.rs diff --git a/air-script/tests/buses/buses_complex_plonky3.rs b/air-script/src/tests/buses/buses_complex_plonky3.rs similarity index 98% rename from air-script/tests/buses/buses_complex_plonky3.rs rename to air-script/src/tests/buses/buses_complex_plonky3.rs index 4b062f2af..4c591450b 100644 --- a/air-script/tests/buses/buses_complex_plonky3.rs +++ b/air-script/src/tests/buses/buses_complex_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 7; pub const AUX_WIDTH: usize = 2; diff --git a/air-script/tests/buses/buses_simple.air b/air-script/src/tests/buses/buses_simple.air similarity index 100% rename from air-script/tests/buses/buses_simple.air rename to air-script/src/tests/buses/buses_simple.air diff --git a/air-script/tests/buses/buses_simple.rs b/air-script/src/tests/buses/buses_simple.rs similarity index 100% rename from air-script/tests/buses/buses_simple.rs rename to air-script/src/tests/buses/buses_simple.rs diff --git a/air-script/tests/buses/buses_simple_plonky3.rs b/air-script/src/tests/buses/buses_simple_plonky3.rs similarity index 95% rename from air-script/tests/buses/buses_simple_plonky3.rs rename to air-script/src/tests/buses/buses_simple_plonky3.rs index 7860bef38..04e55d352 100644 --- a/air-script/tests/buses/buses_simple_plonky3.rs +++ b/air-script/src/tests/buses/buses_simple_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 1; pub const AUX_WIDTH: usize = 2; @@ -54,6 +54,10 @@ impl> AirScriptAir for BusesAir { aux.row_slice(1).unwrap(), ); + // Main boundary constraints + + // Main integrity/transition constraints + // Aux boundary constraints builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); diff --git a/air-script/tests/buses/buses_simple_with_evaluators.air b/air-script/src/tests/buses/buses_simple_with_evaluators.air similarity index 100% rename from air-script/tests/buses/buses_simple_with_evaluators.air rename to air-script/src/tests/buses/buses_simple_with_evaluators.air diff --git a/air-script/src/tests/buses/buses_simple_with_evaluators.rs b/air-script/src/tests/buses/buses_simple_with_evaluators.rs new file mode 100644 index 000000000..b0012a15a --- /dev/null +++ b/air-script/src/tests/buses/buses_simple_with_evaluators.rs @@ -0,0 +1,100 @@ +use winter_air::{Air, AirContext, Assertion, AuxRandElements, EvaluationFrame, ProofOptions as WinterProofOptions, TransitionConstraintDegree, TraceInfo}; +use winter_math::fields::f64::BaseElement as Felt; +use winter_math::{ExtensionOf, FieldElement, ToElements}; +use winter_utils::{ByteWriter, Serializable}; + +pub struct PublicInputs { + inputs: [Felt; 2], +} + +impl PublicInputs { + pub fn new(inputs: [Felt; 2]) -> Self { + Self { inputs } + } +} + +impl Serializable for PublicInputs { + fn write_into(&self, target: &mut W) { + self.inputs.write_into(target); + } +} + +impl ToElements for PublicInputs { + fn to_elements(&self) -> Vec { + let mut elements = Vec::new(); + elements.extend_from_slice(&self.inputs); + elements + } +} + +pub struct BusesAir { + context: AirContext, + inputs: [Felt; 2], +} + +impl BusesAir { + pub fn last_step(&self) -> usize { + self.trace_length() - self.context().num_transition_exemptions() + } +} + +impl Air for BusesAir { + type BaseField = Felt; + type PublicInputs = PublicInputs; + + fn context(&self) -> &AirContext { + &self.context + } + + fn new(trace_info: TraceInfo, public_inputs: PublicInputs, options: WinterProofOptions) -> Self { + let main_degrees = vec![]; + let aux_degrees = vec![TransitionConstraintDegree::new(2), TransitionConstraintDegree::new(1)]; + let num_main_assertions = 0; + let num_aux_assertions = 3; + + let context = AirContext::new_multi_segment( + trace_info, + main_degrees, + aux_degrees, + num_main_assertions, + num_aux_assertions, + options, + ) + .set_num_transition_exemptions(2); + Self { context, inputs: public_inputs.inputs } + } + + fn get_periodic_column_values(&self) -> Vec> { + vec![] + } + + fn get_assertions(&self) -> Vec> { + let mut result = Vec::new(); + result + } + + fn get_aux_assertions>(&self, aux_rand_elements: &AuxRandElements) -> Vec> { + let mut result = Vec::new(); + result.push(Assertion::single(0, self.last_step(), E::ONE)); + result.push(Assertion::single(1, 0, E::ZERO)); + result.push(Assertion::single(1, self.last_step(), E::ZERO)); + result + } + + fn evaluate_transition>(&self, frame: &EvaluationFrame, periodic_values: &[E], result: &mut [E]) { + let main_current = frame.current(); + let main_next = frame.next(); + } + + fn evaluate_aux_transition(&self, main_frame: &EvaluationFrame, aux_frame: &EvaluationFrame, _periodic_values: &[F], aux_rand_elements: &AuxRandElements, result: &mut [E]) + where F: FieldElement, + E: FieldElement + ExtensionOf, + { + let main_current = main_frame.current(); + let main_next = main_frame.next(); + let aux_current = aux_frame.current(); + let aux_next = aux_frame.next(); + result[0] = ((aux_rand_elements.rand_elements()[0] + aux_rand_elements.rand_elements()[1]) * E::from(main_current[0]) + E::ONE - E::from(main_current[0])) * aux_current[0] - ((aux_rand_elements.rand_elements()[0] + aux_rand_elements.rand_elements()[1]) * (E::ONE - E::from(main_current[0])) + E::from(main_current[0])) * aux_next[0]; + result[1] = (aux_rand_elements.rand_elements()[0] + aux_rand_elements.rand_elements()[1] + E::from(Felt::new(2_u64)) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + aux_rand_elements.rand_elements()[1] + E::from(Felt::new(2_u64)) * aux_rand_elements.rand_elements()[2]) * aux_current[1] + (aux_rand_elements.rand_elements()[0] + aux_rand_elements.rand_elements()[1] + E::from(Felt::new(2_u64)) * aux_rand_elements.rand_elements()[2]) * E::from(main_current[0]) - ((aux_rand_elements.rand_elements()[0] + aux_rand_elements.rand_elements()[1] + E::from(Felt::new(2_u64)) * aux_rand_elements.rand_elements()[2]) * (aux_rand_elements.rand_elements()[0] + aux_rand_elements.rand_elements()[1] + E::from(Felt::new(2_u64)) * aux_rand_elements.rand_elements()[2]) * aux_next[1] + (aux_rand_elements.rand_elements()[0] + aux_rand_elements.rand_elements()[1] + E::from(Felt::new(2_u64)) * aux_rand_elements.rand_elements()[2]) * E::from(Felt::new(2_u64))); + } +} \ No newline at end of file diff --git a/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs b/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs new file mode 100644 index 000000000..04e55d352 --- /dev/null +++ b/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs @@ -0,0 +1,76 @@ +use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_matrix::Matrix; +use p3_field::{Field, PrimeCharacteristicRing}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; + +pub const MAIN_WIDTH: usize = 1; +pub const AUX_WIDTH: usize = 2; +pub const NUM_PERIODIC_VALUES: usize = 0; +pub const PERIOD: usize = 0; +pub const NUM_PUBLIC_VALUES: usize = 2; +pub const NUM_ALPHA_CHALLENGES: usize = 2; + +pub struct BusesAir; + +impl BaseAir for BusesAir { + fn width(&self) -> usize { + MAIN_WIDTH + } +} + +impl BaseAirWithPublicValues for BusesAir { + fn num_public_values(&self) -> usize { + NUM_PUBLIC_VALUES + } +} + +impl> AirScriptAir for BusesAir { + fn aux_width(&self) -> usize { + AUX_WIDTH + } + + fn num_alpha_challenges(&self) -> usize { + NUM_ALPHA_CHALLENGES + } + + fn periodic_table(&self) -> Vec> { + vec![] + } + + fn eval(&self, builder: &mut AB) { + let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); + let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let main = builder.main(); + let (main_current, main_next) = ( + main.row_slice(0).unwrap(), + main.row_slice(1).unwrap(), + ); + let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); + let beta = builder.beta(); + let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); + let aux = builder.permutation(); + let (aux_current, aux_next) = ( + aux.row_slice(0).unwrap(), + aux.row_slice(1).unwrap(), + ); + + // Main boundary constraints + + // Main integrity/transition constraints + + // Aux boundary constraints + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); + builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + + // Aux integrity/transition constraints + builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) + AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()).double())); + } +} + +impl Air for BusesAir { + fn eval(&self, builder: &mut AB) { + >::eval(self, builder); + } +} \ No newline at end of file diff --git a/air-script/tests/buses/buses_varlen_boundary_both.air b/air-script/src/tests/buses/buses_varlen_boundary_both.air similarity index 100% rename from air-script/tests/buses/buses_varlen_boundary_both.air rename to air-script/src/tests/buses/buses_varlen_boundary_both.air diff --git a/air-script/tests/buses/buses_varlen_boundary_both.rs b/air-script/src/tests/buses/buses_varlen_boundary_both.rs similarity index 100% rename from air-script/tests/buses/buses_varlen_boundary_both.rs rename to air-script/src/tests/buses/buses_varlen_boundary_both.rs diff --git a/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs similarity index 96% rename from air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs rename to air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs index c44e77ac5..765c24ca9 100644 --- a/air-script/tests/buses/buses_varlen_boundary_both_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 1; pub const AUX_WIDTH: usize = 2; @@ -54,6 +54,10 @@ impl> AirScriptAir for BusesAir { aux.row_slice(1).unwrap(), ); + // Main boundary constraints + + // Main integrity/transition constraints + // Aux boundary constraints builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - aux_bus_boundary_values[0].into()); builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); diff --git a/air-script/tests/buses/buses_varlen_boundary_first.air b/air-script/src/tests/buses/buses_varlen_boundary_first.air similarity index 100% rename from air-script/tests/buses/buses_varlen_boundary_first.air rename to air-script/src/tests/buses/buses_varlen_boundary_first.air diff --git a/air-script/tests/buses/buses_varlen_boundary_first.rs b/air-script/src/tests/buses/buses_varlen_boundary_first.rs similarity index 100% rename from air-script/tests/buses/buses_varlen_boundary_first.rs rename to air-script/src/tests/buses/buses_varlen_boundary_first.rs diff --git a/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs similarity index 96% rename from air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs rename to air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs index a236a1336..686ba6582 100644 --- a/air-script/tests/buses/buses_varlen_boundary_first_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 1; pub const AUX_WIDTH: usize = 2; @@ -54,6 +54,10 @@ impl> AirScriptAir for BusesAir { aux.row_slice(1).unwrap(), ); + // Main boundary constraints + + // Main integrity/transition constraints + // Aux boundary constraints builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - aux_bus_boundary_values[0].into()); builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); diff --git a/air-script/tests/buses/buses_varlen_boundary_last.air b/air-script/src/tests/buses/buses_varlen_boundary_last.air similarity index 100% rename from air-script/tests/buses/buses_varlen_boundary_last.air rename to air-script/src/tests/buses/buses_varlen_boundary_last.air diff --git a/air-script/tests/buses/buses_varlen_boundary_last.rs b/air-script/src/tests/buses/buses_varlen_boundary_last.rs similarity index 100% rename from air-script/tests/buses/buses_varlen_boundary_last.rs rename to air-script/src/tests/buses/buses_varlen_boundary_last.rs diff --git a/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs similarity index 96% rename from air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs rename to air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs index 5099d3f0b..b381f0dcf 100644 --- a/air-script/tests/buses/buses_varlen_boundary_last_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 1; pub const AUX_WIDTH: usize = 2; @@ -54,6 +54,10 @@ impl> AirScriptAir for BusesAir { aux.row_slice(1).unwrap(), ); + // Main boundary constraints + + // Main integrity/transition constraints + // Aux boundary constraints builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - aux_bus_boundary_values[0].into()); diff --git a/air-script/tests/buses/mod.rs b/air-script/src/tests/buses/mod.rs similarity index 100% rename from air-script/tests/buses/mod.rs rename to air-script/src/tests/buses/mod.rs diff --git a/air-script/tests/buses/test_air_plonky3.rs b/air-script/src/tests/buses/test_air_plonky3.rs similarity index 94% rename from air-script/tests/buses/test_air_plonky3.rs rename to air-script/src/tests/buses/test_air_plonky3.rs index 3f5af2f25..6b818e844 100644 --- a/air-script/tests/buses/test_air_plonky3.rs +++ b/air-script/src/tests/buses/test_air_plonky3.rs @@ -13,9 +13,9 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - buses::buses_complex_plonky3::{BusesAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::buses::buses_complex_plonky3::{BusesAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/buses/test_air_winterfell.rs b/air-script/src/tests/buses/test_air_winterfell.rs similarity index 92% rename from air-script/tests/buses/test_air_winterfell.rs rename to air-script/src/tests/buses/test_air_winterfell.rs index a2e07196d..150617152 100644 --- a/air-script/tests/buses/test_air_winterfell.rs +++ b/air-script/src/tests/buses/test_air_winterfell.rs @@ -3,9 +3,9 @@ use winter_math::fields::f64::BaseElement as Felt; use winterfell::{AuxTraceWithMetadata, Trace, TraceTable, matrix::ColMatrix}; use crate::{ - buses::buses_complex::PublicInputs, generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::buses::buses_complex::PublicInputs, }; #[derive(Clone)] @@ -63,7 +63,7 @@ impl AirTester for BusesAirTester { generate_air_winterfell_test!( test_buses_air, - crate::buses::buses_complex::BusesAir, + crate::tests::buses::buses_complex::BusesAir, BusesAirTester, 1024 ); diff --git a/air-script/tests/computed_indices/computed_indices_complex.air b/air-script/src/tests/computed_indices/computed_indices_complex.air similarity index 100% rename from air-script/tests/computed_indices/computed_indices_complex.air rename to air-script/src/tests/computed_indices/computed_indices_complex.air diff --git a/air-script/tests/computed_indices/computed_indices_complex.rs b/air-script/src/tests/computed_indices/computed_indices_complex.rs similarity index 100% rename from air-script/tests/computed_indices/computed_indices_complex.rs rename to air-script/src/tests/computed_indices/computed_indices_complex.rs diff --git a/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs b/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs similarity index 92% rename from air-script/tests/computed_indices/computed_indices_complex_plonky3.rs rename to air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs index f39db8e83..004a28231 100644 --- a/air-script/tests/computed_indices/computed_indices_complex_plonky3.rs +++ b/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -51,6 +51,10 @@ impl> AirScriptAir for ComputedIndi // Main integrity/transition constraints builder.assert_zero(main_current[2].clone().into() * AB::Expr::from_u64(3) + main_current[3].clone().into() * AB::Expr::from_u64(4)); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/computed_indices/computed_indices_simple.air b/air-script/src/tests/computed_indices/computed_indices_simple.air similarity index 100% rename from air-script/tests/computed_indices/computed_indices_simple.air rename to air-script/src/tests/computed_indices/computed_indices_simple.air diff --git a/air-script/tests/computed_indices/computed_indices_simple.rs b/air-script/src/tests/computed_indices/computed_indices_simple.rs similarity index 100% rename from air-script/tests/computed_indices/computed_indices_simple.rs rename to air-script/src/tests/computed_indices/computed_indices_simple.rs diff --git a/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs b/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs similarity index 94% rename from air-script/tests/computed_indices/computed_indices_simple_plonky3.rs rename to air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs index 4801d1b57..f9427c8a4 100644 --- a/air-script/tests/computed_indices/computed_indices_simple_plonky3.rs +++ b/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 8; pub const AUX_WIDTH: usize = 0; @@ -58,6 +58,10 @@ impl> AirScriptAir for ComputedIndi builder.when_transition().assert_zero(main_next[5].clone().into() - main_current[5].clone().into().double()); builder.when_transition().assert_zero(main_next[6].clone().into() - AB::Expr::from_u64(6) * main_current[6].clone().into()); builder.when_transition().assert_zero(main_next[7].clone().into() - AB::Expr::from_u64(12) * main_current[7].clone().into()); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/src/tests/computed_indices/mod.rs b/air-script/src/tests/computed_indices/mod.rs new file mode 100644 index 000000000..948afee49 --- /dev/null +++ b/air-script/src/tests/computed_indices/mod.rs @@ -0,0 +1,18 @@ +#[rustfmt::skip] +#[allow(clippy::all)] +mod computed_indices_complex; +#[rustfmt::skip] +#[allow(clippy::all)] +mod computed_indices_simple; + +#[rustfmt::skip] +#[allow(clippy::all)] +#[allow(unused_imports)] +mod computed_indices_complex_plonky3; +#[rustfmt::skip] +#[allow(clippy::all)] +#[allow(unused_imports)] +mod computed_indices_simple_plonky3; + +mod test_air_plonky3; +mod test_air_winterfell; diff --git a/air-script/src/tests/computed_indices/test_air_plonky3.rs b/air-script/src/tests/computed_indices/test_air_plonky3.rs new file mode 100644 index 000000000..e8eb0f244 --- /dev/null +++ b/air-script/src/tests/computed_indices/test_air_plonky3.rs @@ -0,0 +1,73 @@ +use std::marker::PhantomData; + +use p3_challenger::{HashChallenger, SerializingChallenger64}; +use p3_circle::CirclePcs; +use p3_commit::ExtensionMmcs; +use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; +use p3_fri::create_benchmark_fri_params; +use p3_goldilocks::Goldilocks; +use p3_matrix::dense::RowMajorMatrix; +use p3_merkle_tree::MerkleTreeMmcs; +use p3_sha256::Sha256; +use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; +use p3_uni_stark::StarkConfig; + +use crate::{ + generate_air_plonky3_test_with_airscript_traits, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::computed_indices::computed_indices_simple_plonky3::{ComputedIndicesAir, MAIN_WIDTH}, +}; + +pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { + let num_rows = 32; + let trace_length = num_rows * MAIN_WIDTH; + + let mut long_trace = F::zero_vec(trace_length); + + let mut trace = RowMajorMatrix::new(long_trace, MAIN_WIDTH); + + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[F; MAIN_WIDTH]>() }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(rows.len(), num_rows); + + // Initialize first row + rows[0][0] = F::ZERO; + rows[0][1] = F::from_canonical_checked(2).unwrap(); + rows[0][2] = F::from_canonical_checked(4).unwrap(); + rows[0][3] = F::from_canonical_checked(6).unwrap(); + rows[0][4] = F::ZERO; + rows[0][5] = F::ZERO; + rows[0][6] = F::ZERO; + rows[0][7] = F::ZERO; + + // Fill subsequent rows using direct access to the rows array + for i in 1..num_rows { + let col_0_prev = rows[i - 1][0]; + let col_1_prev = rows[i - 1][1]; + let col_2_prev = rows[i - 1][2]; + let col_3_prev = rows[i - 1][3]; + let col_4_prev = rows[i - 1][4]; + let col_5_prev = rows[i - 1][5]; + let col_6_prev = rows[i - 1][6]; + let col_7_prev = rows[i - 1][7]; + + // Update current row based on previous values + rows[i][0] = col_0_prev; + rows[i][1] = col_1_prev; + rows[i][2] = col_2_prev; + rows[i][3] = col_3_prev; + rows[i][4] = col_4_prev * F::ZERO; + rows[i][5] = col_5_prev * F::from_canonical_checked(2).unwrap(); + rows[i][6] = col_6_prev * F::from_canonical_checked(6).unwrap(); + rows[i][7] = col_7_prev * F::from_canonical_checked(12).unwrap(); + } + + trace +} + +fn generate_inputs() -> Vec { + vec![1; 16] +} + +generate_air_plonky3_test_with_airscript_traits!(test_air_plonky3, ComputedIndicesAir); diff --git a/air-script/tests/computed_indices/test_air.rs b/air-script/src/tests/computed_indices/test_air_winterfell.rs similarity index 63% rename from air-script/tests/computed_indices/test_air.rs rename to air-script/src/tests/computed_indices/test_air_winterfell.rs index 5a953f6e5..1f7e35ed3 100644 --- a/air-script/tests/computed_indices/test_air.rs +++ b/air-script/src/tests/computed_indices/test_air_winterfell.rs @@ -3,8 +3,9 @@ use winter_math::fields::f64::BaseElement as Felt; use winterfell::{Trace, TraceTable}; use crate::{ - computed_indices::computed_indices_simple::{ComputedIndicesAir, PublicInputs}, - helpers::{AirTester, MyTraceTable}, + generate_air_winterfell_test, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::computed_indices::computed_indices_simple::PublicInputs, }; #[derive(Clone)] @@ -45,17 +46,9 @@ impl AirTester for ComputedIndicesAirTester { } } -#[test] -fn test_computed_indices_air() { - let air_tester = Box::new(ComputedIndicesAirTester {}); - let length = 1024; - - let main_trace = air_tester.build_main_trace(length); - let aux_trace = air_tester.build_aux_trace(length); - let pub_inputs = air_tester.public_inputs(); - let trace_info = air_tester.build_trace_info(length); - let options = air_tester.build_proof_options(); - - let air = ComputedIndicesAir::new(trace_info, pub_inputs, options); - main_trace.validate::(&air, aux_trace.as_ref()); -} +generate_air_winterfell_test!( + test_computed_indices_air, + crate::tests::computed_indices::computed_indices_simple::ComputedIndicesAir, + ComputedIndicesAirTester, + 1024 +); diff --git a/air-script/tests/constant_in_range/constant_in_range.air b/air-script/src/tests/constant_in_range/constant_in_range.air similarity index 100% rename from air-script/tests/constant_in_range/constant_in_range.air rename to air-script/src/tests/constant_in_range/constant_in_range.air diff --git a/air-script/tests/constant_in_range/constant_in_range.rs b/air-script/src/tests/constant_in_range/constant_in_range.rs similarity index 100% rename from air-script/tests/constant_in_range/constant_in_range.rs rename to air-script/src/tests/constant_in_range/constant_in_range.rs diff --git a/air-script/tests/constant_in_range/constant_in_range_module.air b/air-script/src/tests/constant_in_range/constant_in_range_module.air similarity index 100% rename from air-script/tests/constant_in_range/constant_in_range_module.air rename to air-script/src/tests/constant_in_range/constant_in_range_module.air diff --git a/air-script/tests/constant_in_range/constant_in_range_plonky3.rs b/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs similarity index 93% rename from air-script/tests/constant_in_range/constant_in_range_plonky3.rs rename to air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs index d946455fd..26fe443f6 100644 --- a/air-script/tests/constant_in_range/constant_in_range_plonky3.rs +++ b/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 12; pub const AUX_WIDTH: usize = 0; @@ -51,6 +51,10 @@ impl> AirScriptAir for ConstantInRa // Main integrity/transition constraints builder.assert_zero(main_current[0].clone().into() - (main_current[1].clone().into() - main_current[4].clone().into() - main_current[8].clone().into() + AB::Expr::ONE + main_current[2].clone().into() - main_current[5].clone().into() - main_current[9].clone().into() + AB::Expr::from_u64(2) + main_current[3].clone().into() - main_current[6].clone().into() - main_current[10].clone().into())); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/constant_in_range/mod.rs b/air-script/src/tests/constant_in_range/mod.rs similarity index 100% rename from air-script/tests/constant_in_range/mod.rs rename to air-script/src/tests/constant_in_range/mod.rs diff --git a/air-script/tests/constant_in_range/test_air_plonky3.rs b/air-script/src/tests/constant_in_range/test_air_plonky3.rs similarity index 93% rename from air-script/tests/constant_in_range/test_air_plonky3.rs rename to air-script/src/tests/constant_in_range/test_air_plonky3.rs index 2857f5648..160c681bc 100644 --- a/air-script/tests/constant_in_range/test_air_plonky3.rs +++ b/air-script/src/tests/constant_in_range/test_air_plonky3.rs @@ -13,9 +13,9 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - constant_in_range::constant_in_range_plonky3::{ConstantInRangeAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::constant_in_range::constant_in_range_plonky3::{ConstantInRangeAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/constant_in_range/test_air_winterfell.rs b/air-script/src/tests/constant_in_range/test_air_winterfell.rs similarity index 86% rename from air-script/tests/constant_in_range/test_air_winterfell.rs rename to air-script/src/tests/constant_in_range/test_air_winterfell.rs index 3672378c8..c08fa18ab 100644 --- a/air-script/tests/constant_in_range/test_air_winterfell.rs +++ b/air-script/src/tests/constant_in_range/test_air_winterfell.rs @@ -3,9 +3,9 @@ use winter_math::fields::f64::BaseElement as Felt; use winterfell::{Trace, TraceTable}; use crate::{ - constant_in_range::constant_in_range::PublicInputs, generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::constant_in_range::constant_in_range::PublicInputs, }; #[derive(Clone)] @@ -48,7 +48,7 @@ impl AirTester for ConstantInRangeAirTester { generate_air_winterfell_test!( test_constant_in_range_air, - crate::constant_in_range::constant_in_range::ConstantInRangeAir, + crate::tests::constant_in_range::constant_in_range::ConstantInRangeAir, ConstantInRangeAirTester, 1024 ); diff --git a/air-script/tests/constants/constants.air b/air-script/src/tests/constants/constants.air similarity index 100% rename from air-script/tests/constants/constants.air rename to air-script/src/tests/constants/constants.air diff --git a/air-script/tests/constants/constants.rs b/air-script/src/tests/constants/constants.rs similarity index 100% rename from air-script/tests/constants/constants.rs rename to air-script/src/tests/constants/constants.rs diff --git a/air-script/tests/constants/constants_plonky3.rs b/air-script/src/tests/constants/constants_plonky3.rs similarity index 94% rename from air-script/tests/constants/constants_plonky3.rs rename to air-script/src/tests/constants/constants_plonky3.rs index 1864d37c6..83e3bd4a5 100644 --- a/air-script/tests/constants/constants_plonky3.rs +++ b/air-script/src/tests/constants/constants_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 7; pub const AUX_WIDTH: usize = 0; @@ -60,6 +60,10 @@ impl> AirScriptAir for ConstantsAir builder.when_transition().assert_zero(main_next[2].clone().into() - main_current[2].clone().into()); builder.when_transition().assert_zero(main_next[5].clone().into() - (main_current[5].clone().into() + AB::Expr::ONE)); builder.assert_zero(main_current[4].clone().into() - AB::Expr::ONE); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/constants/mod.rs b/air-script/src/tests/constants/mod.rs similarity index 100% rename from air-script/tests/constants/mod.rs rename to air-script/src/tests/constants/mod.rs diff --git a/air-script/tests/constants/test_air_plonky3.rs b/air-script/src/tests/constants/test_air_plonky3.rs similarity index 93% rename from air-script/tests/constants/test_air_plonky3.rs rename to air-script/src/tests/constants/test_air_plonky3.rs index 5499b69ae..42fcdc199 100644 --- a/air-script/tests/constants/test_air_plonky3.rs +++ b/air-script/src/tests/constants/test_air_plonky3.rs @@ -13,9 +13,9 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - constants::constants_plonky3::{ConstantsAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::constants::constants_plonky3::{ConstantsAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/constants/test_air_winterfell.rs b/air-script/src/tests/constants/test_air_winterfell.rs similarity index 88% rename from air-script/tests/constants/test_air_winterfell.rs rename to air-script/src/tests/constants/test_air_winterfell.rs index 9459000d7..926c8c77c 100644 --- a/air-script/tests/constants/test_air_winterfell.rs +++ b/air-script/src/tests/constants/test_air_winterfell.rs @@ -3,9 +3,9 @@ use winter_math::fields::f64::BaseElement as Felt; use winterfell::{Trace, TraceTable}; use crate::{ - constants::constants::PublicInputs, generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::constants::constants::PublicInputs, }; #[derive(Clone)] @@ -46,7 +46,7 @@ impl AirTester for ConstantsAirTester { generate_air_winterfell_test!( test_constants_air, - crate::constants::constants::ConstantsAir, + crate::tests::constants::constants::ConstantsAir, ConstantsAirTester, 1024 ); diff --git a/air-script/tests/constraint_comprehension/cc_with_evaluators.air b/air-script/src/tests/constraint_comprehension/cc_with_evaluators.air similarity index 100% rename from air-script/tests/constraint_comprehension/cc_with_evaluators.air rename to air-script/src/tests/constraint_comprehension/cc_with_evaluators.air diff --git a/air-script/tests/constraint_comprehension/constraint_comprehension.air b/air-script/src/tests/constraint_comprehension/constraint_comprehension.air similarity index 100% rename from air-script/tests/constraint_comprehension/constraint_comprehension.air rename to air-script/src/tests/constraint_comprehension/constraint_comprehension.air diff --git a/air-script/tests/constraint_comprehension/constraint_comprehension.rs b/air-script/src/tests/constraint_comprehension/constraint_comprehension.rs similarity index 100% rename from air-script/tests/constraint_comprehension/constraint_comprehension.rs rename to air-script/src/tests/constraint_comprehension/constraint_comprehension.rs diff --git a/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs b/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs similarity index 93% rename from air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs rename to air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs index b2f6449e8..5d08db73c 100644 --- a/air-script/tests/constraint_comprehension/constraint_comprehension_plonky3.rs +++ b/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 14; pub const AUX_WIDTH: usize = 0; @@ -54,6 +54,10 @@ impl> AirScriptAir for ConstraintCo builder.assert_zero(main_current[7].clone().into() - main_current[11].clone().into()); builder.assert_zero(main_current[8].clone().into() - main_current[12].clone().into()); builder.assert_zero(main_current[9].clone().into() - main_current[13].clone().into()); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/constraint_comprehension/mod.rs b/air-script/src/tests/constraint_comprehension/mod.rs similarity index 100% rename from air-script/tests/constraint_comprehension/mod.rs rename to air-script/src/tests/constraint_comprehension/mod.rs diff --git a/air-script/tests/constraint_comprehension/test_air_plonky3.rs b/air-script/src/tests/constraint_comprehension/test_air_plonky3.rs similarity index 92% rename from air-script/tests/constraint_comprehension/test_air_plonky3.rs rename to air-script/src/tests/constraint_comprehension/test_air_plonky3.rs index e5a1658ca..b5c290df4 100644 --- a/air-script/tests/constraint_comprehension/test_air_plonky3.rs +++ b/air-script/src/tests/constraint_comprehension/test_air_plonky3.rs @@ -13,11 +13,11 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - constraint_comprehension::constraint_comprehension_plonky3::{ + generate_air_plonky3_test_with_airscript_traits, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::constraint_comprehension::constraint_comprehension_plonky3::{ ConstraintComprehensionAir, MAIN_WIDTH, }, - generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/constraint_comprehension/test_air_winterfell.rs b/air-script/src/tests/constraint_comprehension/test_air_winterfell.rs similarity index 85% rename from air-script/tests/constraint_comprehension/test_air_winterfell.rs rename to air-script/src/tests/constraint_comprehension/test_air_winterfell.rs index 73a24bf0f..d4bec18d1 100644 --- a/air-script/tests/constraint_comprehension/test_air_winterfell.rs +++ b/air-script/src/tests/constraint_comprehension/test_air_winterfell.rs @@ -3,9 +3,9 @@ use winter_math::fields::f64::BaseElement as Felt; use winterfell::{Trace, TraceTable}; use crate::{ - constraint_comprehension::constraint_comprehension::PublicInputs, generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::constraint_comprehension::constraint_comprehension::PublicInputs, }; #[derive(Clone)] @@ -50,7 +50,7 @@ impl AirTester for ConstraintComprehensionAirTester { generate_air_winterfell_test!( test_constraint_comprehension_air, - crate::constraint_comprehension::constraint_comprehension::ConstraintComprehensionAir, + crate::tests::constraint_comprehension::constraint_comprehension::ConstraintComprehensionAir, ConstraintComprehensionAirTester, 1024 ); diff --git a/air-script/tests/docs_sync.rs b/air-script/src/tests/docs_sync.rs similarity index 100% rename from air-script/tests/docs_sync.rs rename to air-script/src/tests/docs_sync.rs diff --git a/air-script/tests/evaluators/evaluators.air b/air-script/src/tests/evaluators/evaluators.air similarity index 100% rename from air-script/tests/evaluators/evaluators.air rename to air-script/src/tests/evaluators/evaluators.air diff --git a/air-script/tests/evaluators/evaluators.rs b/air-script/src/tests/evaluators/evaluators.rs similarity index 100% rename from air-script/tests/evaluators/evaluators.rs rename to air-script/src/tests/evaluators/evaluators.rs diff --git a/air-script/tests/evaluators/evaluators_plonky3.rs b/air-script/src/tests/evaluators/evaluators_plonky3.rs similarity index 94% rename from air-script/tests/evaluators/evaluators_plonky3.rs rename to air-script/src/tests/evaluators/evaluators_plonky3.rs index 5761dd95c..481e87758 100644 --- a/air-script/tests/evaluators/evaluators_plonky3.rs +++ b/air-script/src/tests/evaluators/evaluators_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 7; pub const AUX_WIDTH: usize = 0; @@ -60,6 +60,10 @@ impl> AirScriptAir for EvaluatorsAi builder.assert_zero(main_current[4].clone().into()); builder.assert_zero(main_current[5].clone().into() - AB::Expr::ONE); builder.assert_zero(main_current[6].clone().into() - AB::Expr::from_u64(4)); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/evaluators/mod.rs b/air-script/src/tests/evaluators/mod.rs similarity index 100% rename from air-script/tests/evaluators/mod.rs rename to air-script/src/tests/evaluators/mod.rs diff --git a/air-script/tests/evaluators/test_air_plonky3.rs b/air-script/src/tests/evaluators/test_air_plonky3.rs similarity index 93% rename from air-script/tests/evaluators/test_air_plonky3.rs rename to air-script/src/tests/evaluators/test_air_plonky3.rs index 891bac58a..b06040a1f 100644 --- a/air-script/tests/evaluators/test_air_plonky3.rs +++ b/air-script/src/tests/evaluators/test_air_plonky3.rs @@ -13,9 +13,9 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - evaluators::evaluators_plonky3::{EvaluatorsAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::evaluators::evaluators_plonky3::{EvaluatorsAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/evaluators/test_air_winterfell.rs b/air-script/src/tests/evaluators/test_air_winterfell.rs similarity index 86% rename from air-script/tests/evaluators/test_air_winterfell.rs rename to air-script/src/tests/evaluators/test_air_winterfell.rs index fa8f6f6d8..bbaeb5ecd 100644 --- a/air-script/tests/evaluators/test_air_winterfell.rs +++ b/air-script/src/tests/evaluators/test_air_winterfell.rs @@ -3,9 +3,9 @@ use winter_math::{FieldElement, fields::f64::BaseElement as Felt}; use winterfell::{Trace, TraceTable}; use crate::{ - evaluators::evaluators::PublicInputs, generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::evaluators::evaluators::PublicInputs, }; #[derive(Clone)] @@ -43,7 +43,7 @@ impl AirTester for EvaluatorsAirTester { generate_air_winterfell_test!( test_evaluators_air, - crate::evaluators::evaluators::EvaluatorsAir, + crate::tests::evaluators::evaluators::EvaluatorsAir, EvaluatorsAirTester, 1024 ); diff --git a/air-script/tests/fibonacci/fibonacci.air b/air-script/src/tests/fibonacci/fibonacci.air similarity index 100% rename from air-script/tests/fibonacci/fibonacci.air rename to air-script/src/tests/fibonacci/fibonacci.air diff --git a/air-script/tests/fibonacci/fibonacci.rs b/air-script/src/tests/fibonacci/fibonacci.rs similarity index 100% rename from air-script/tests/fibonacci/fibonacci.rs rename to air-script/src/tests/fibonacci/fibonacci.rs diff --git a/air-script/tests/fibonacci/fibonacci_plonky3.rs b/air-script/src/tests/fibonacci/fibonacci_plonky3.rs similarity index 93% rename from air-script/tests/fibonacci/fibonacci_plonky3.rs rename to air-script/src/tests/fibonacci/fibonacci_plonky3.rs index 5cd24c62c..7bd59a684 100644 --- a/air-script/tests/fibonacci/fibonacci_plonky3.rs +++ b/air-script/src/tests/fibonacci/fibonacci_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 2; pub const AUX_WIDTH: usize = 0; @@ -54,6 +54,10 @@ impl> AirScriptAir for FibonacciAir // Main integrity/transition constraints builder.when_transition().assert_zero(main_next[1].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())); builder.when_transition().assert_zero(main_next[0].clone().into() - main_current[1].clone().into()); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/fibonacci/mod.rs b/air-script/src/tests/fibonacci/mod.rs similarity index 100% rename from air-script/tests/fibonacci/mod.rs rename to air-script/src/tests/fibonacci/mod.rs diff --git a/air-script/tests/fibonacci/test_air_plonky3.rs b/air-script/src/tests/fibonacci/test_air_plonky3.rs similarity index 92% rename from air-script/tests/fibonacci/test_air_plonky3.rs rename to air-script/src/tests/fibonacci/test_air_plonky3.rs index 3725fdf9b..8596f5106 100644 --- a/air-script/tests/fibonacci/test_air_plonky3.rs +++ b/air-script/src/tests/fibonacci/test_air_plonky3.rs @@ -13,9 +13,9 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - fibonacci::fibonacci_plonky3::{FibonacciAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::fibonacci::fibonacci_plonky3::{FibonacciAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/fibonacci/test_air_winterfell.rs b/air-script/src/tests/fibonacci/test_air_winterfell.rs similarity index 88% rename from air-script/tests/fibonacci/test_air_winterfell.rs rename to air-script/src/tests/fibonacci/test_air_winterfell.rs index 5839643d7..9d2313823 100644 --- a/air-script/tests/fibonacci/test_air_winterfell.rs +++ b/air-script/src/tests/fibonacci/test_air_winterfell.rs @@ -5,9 +5,9 @@ use winter_math::fields::f64::BaseElement as Felt; use winterfell::{AuxTraceWithMetadata, Trace, TraceTable, matrix::ColMatrix}; use crate::{ - fibonacci::fibonacci::PublicInputs, generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::fibonacci::fibonacci::PublicInputs, }; #[derive(Clone)] @@ -47,7 +47,7 @@ impl AirTester for FibonacciAirTester { generate_air_winterfell_test!( test_fibonacci_air, - crate::fibonacci::fibonacci::FibonacciAir, + crate::tests::fibonacci::fibonacci::FibonacciAir, FibonacciAirTester, 32 ); diff --git a/air-script/tests/functions/functions_complex.air b/air-script/src/tests/functions/functions_complex.air similarity index 100% rename from air-script/tests/functions/functions_complex.air rename to air-script/src/tests/functions/functions_complex.air diff --git a/air-script/tests/functions/functions_complex.rs b/air-script/src/tests/functions/functions_complex.rs similarity index 100% rename from air-script/tests/functions/functions_complex.rs rename to air-script/src/tests/functions/functions_complex.rs diff --git a/air-script/tests/functions/functions_complex_plonky3.rs b/air-script/src/tests/functions/functions_complex_plonky3.rs similarity index 95% rename from air-script/tests/functions/functions_complex_plonky3.rs rename to air-script/src/tests/functions/functions_complex_plonky3.rs index e1b1c46be..089a72eb2 100644 --- a/air-script/tests/functions/functions_complex_plonky3.rs +++ b/air-script/src/tests/functions/functions_complex_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 17; pub const AUX_WIDTH: usize = 0; @@ -52,6 +52,10 @@ impl> AirScriptAir for FunctionsAir // Main integrity/transition constraints builder.when_transition().assert_zero(main_next[16].clone().into() - main_current[16].clone().into() * ((main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[3].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() + main_current[3].clone().into() * main_current[3].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_current[2].clone().into() + main_current[3].clone().into() * main_current[1].clone().into() * (AB::Expr::ONE - main_current[2].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into())) * main_current[0].clone().into() - main_current[0].clone().into() + AB::Expr::ONE)); builder.when_transition().assert_zero(main_next[3].clone().into() - (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() + main_current[8].clone().into() + main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() + main_current[14].clone().into() + main_current[15].clone().into() + AB::Expr::ONE).double()); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/functions/functions_simple.air b/air-script/src/tests/functions/functions_simple.air similarity index 100% rename from air-script/tests/functions/functions_simple.air rename to air-script/src/tests/functions/functions_simple.air diff --git a/air-script/tests/functions/functions_simple.rs b/air-script/src/tests/functions/functions_simple.rs similarity index 100% rename from air-script/tests/functions/functions_simple.rs rename to air-script/src/tests/functions/functions_simple.rs diff --git a/air-script/tests/functions/functions_simple_plonky3.rs b/air-script/src/tests/functions/functions_simple_plonky3.rs similarity index 95% rename from air-script/tests/functions/functions_simple_plonky3.rs rename to air-script/src/tests/functions/functions_simple_plonky3.rs index 61632e6ef..75151732c 100644 --- a/air-script/tests/functions/functions_simple_plonky3.rs +++ b/air-script/src/tests/functions/functions_simple_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 9; pub const AUX_WIDTH: usize = 0; @@ -58,6 +58,10 @@ impl> AirScriptAir for FunctionsAir builder.assert_zero(main_current[1].clone().into() + (main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * main_current[4].clone().into() * main_current[5].clone().into() * main_current[6].clone().into() * main_current[7].clone().into() - AB::Expr::ONE); builder.assert_zero(main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into() - AB::Expr::ONE); builder.assert_zero((main_current[4].clone().into() + main_current[5].clone().into() + main_current[6].clone().into() + main_current[7].clone().into()) * AB::Expr::from_u64(4) - AB::Expr::ONE); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/functions/inlined_functions_simple.air b/air-script/src/tests/functions/inlined_functions_simple.air similarity index 100% rename from air-script/tests/functions/inlined_functions_simple.air rename to air-script/src/tests/functions/inlined_functions_simple.air diff --git a/air-script/tests/functions/mod.rs b/air-script/src/tests/functions/mod.rs similarity index 100% rename from air-script/tests/functions/mod.rs rename to air-script/src/tests/functions/mod.rs diff --git a/air-script/tests/functions/test_air_plonky3.rs b/air-script/src/tests/functions/test_air_plonky3.rs similarity index 95% rename from air-script/tests/functions/test_air_plonky3.rs rename to air-script/src/tests/functions/test_air_plonky3.rs index ddea4098d..b95913e4d 100644 --- a/air-script/tests/functions/test_air_plonky3.rs +++ b/air-script/src/tests/functions/test_air_plonky3.rs @@ -13,9 +13,9 @@ use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; use p3_uni_stark::StarkConfig; use crate::{ - functions::functions_complex_plonky3::{FunctionsAir, MAIN_WIDTH}, generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::functions::functions_complex_plonky3::{FunctionsAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/functions/test_air_winterfell.rs b/air-script/src/tests/functions/test_air_winterfell.rs similarity index 92% rename from air-script/tests/functions/test_air_winterfell.rs rename to air-script/src/tests/functions/test_air_winterfell.rs index 0357e9039..76aa0b6f3 100644 --- a/air-script/tests/functions/test_air_winterfell.rs +++ b/air-script/src/tests/functions/test_air_winterfell.rs @@ -3,9 +3,9 @@ use winter_math::fields::f64::BaseElement as Felt; use winterfell::{Trace, TraceTable}; use crate::{ - functions::functions_complex::PublicInputs, generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::functions::functions_complex::PublicInputs, }; #[derive(Clone)] @@ -70,7 +70,7 @@ impl AirTester for FunctionsAirTester { generate_air_winterfell_test!( test_functions_complex_air, - crate::functions::functions_complex::FunctionsAir, + crate::tests::functions::functions_complex::FunctionsAir, FunctionsAirTester, 1024 ); diff --git a/air-script/tests/indexed_trace_access/indexed_trace_access.air b/air-script/src/tests/indexed_trace_access/indexed_trace_access.air similarity index 100% rename from air-script/tests/indexed_trace_access/indexed_trace_access.air rename to air-script/src/tests/indexed_trace_access/indexed_trace_access.air diff --git a/air-script/tests/indexed_trace_access/indexed_trace_access.rs b/air-script/src/tests/indexed_trace_access/indexed_trace_access.rs similarity index 100% rename from air-script/tests/indexed_trace_access/indexed_trace_access.rs rename to air-script/src/tests/indexed_trace_access/indexed_trace_access.rs diff --git a/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs b/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs similarity index 92% rename from air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs rename to air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs index 1753a4967..35046650a 100644 --- a/air-script/tests/indexed_trace_access/indexed_trace_access_plonky3.rs +++ b/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -51,6 +51,10 @@ impl> AirScriptAir for TraceAccessA // Main integrity/transition constraints builder.when_transition().assert_zero(main_next[0].clone().into() - (main_current[1].clone().into() + AB::Expr::ONE)); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/indexed_trace_access/mod.rs b/air-script/src/tests/indexed_trace_access/mod.rs similarity index 100% rename from air-script/tests/indexed_trace_access/mod.rs rename to air-script/src/tests/indexed_trace_access/mod.rs diff --git a/air-script/tests/indexed_trace_access/test_air_plonky3.rs b/air-script/src/tests/indexed_trace_access/test_air_plonky3.rs similarity index 90% rename from air-script/tests/indexed_trace_access/test_air_plonky3.rs rename to air-script/src/tests/indexed_trace_access/test_air_plonky3.rs index 6cc8a63f3..7c2cea5ab 100644 --- a/air-script/tests/indexed_trace_access/test_air_plonky3.rs +++ b/air-script/src/tests/indexed_trace_access/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, - indexed_trace_access::indexed_trace_access_plonky3::{MAIN_WIDTH, TraceAccessAir}, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::indexed_trace_access::indexed_trace_access_plonky3::{MAIN_WIDTH, TraceAccessAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/indexed_trace_access/test_air_winterfell.rs b/air-script/src/tests/indexed_trace_access/test_air_winterfell.rs similarity index 83% rename from air-script/tests/indexed_trace_access/test_air_winterfell.rs rename to air-script/src/tests/indexed_trace_access/test_air_winterfell.rs index 9d7e64bcb..44b7dfcec 100644 --- a/air-script/tests/indexed_trace_access/test_air_winterfell.rs +++ b/air-script/src/tests/indexed_trace_access/test_air_winterfell.rs @@ -4,8 +4,8 @@ use winterfell::{Trace, TraceTable}; use crate::{ generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, - indexed_trace_access::indexed_trace_access::PublicInputs, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::indexed_trace_access::indexed_trace_access::PublicInputs, }; #[derive(Clone)] @@ -42,7 +42,7 @@ impl AirTester for TraceAccessAirTester { generate_air_winterfell_test!( test_indexed_trace_access_air, - crate::indexed_trace_access::indexed_trace_access::TraceAccessAir, + crate::tests::indexed_trace_access::indexed_trace_access::TraceAccessAir, TraceAccessAirTester, 1024 ); diff --git a/air-script/tests/list_comprehension/list_comprehension.air b/air-script/src/tests/list_comprehension/list_comprehension.air similarity index 100% rename from air-script/tests/list_comprehension/list_comprehension.air rename to air-script/src/tests/list_comprehension/list_comprehension.air diff --git a/air-script/tests/list_comprehension/list_comprehension.rs b/air-script/src/tests/list_comprehension/list_comprehension.rs similarity index 100% rename from air-script/tests/list_comprehension/list_comprehension.rs rename to air-script/src/tests/list_comprehension/list_comprehension.rs diff --git a/air-script/tests/list_comprehension/list_comprehension_nested.air b/air-script/src/tests/list_comprehension/list_comprehension_nested.air similarity index 100% rename from air-script/tests/list_comprehension/list_comprehension_nested.air rename to air-script/src/tests/list_comprehension/list_comprehension_nested.air diff --git a/air-script/tests/list_comprehension/list_comprehension_nested.rs b/air-script/src/tests/list_comprehension/list_comprehension_nested.rs similarity index 100% rename from air-script/tests/list_comprehension/list_comprehension_nested.rs rename to air-script/src/tests/list_comprehension/list_comprehension_nested.rs diff --git a/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs b/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs similarity index 93% rename from air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs rename to air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs index 94cc649b9..de5ed76ba 100644 --- a/air-script/tests/list_comprehension/list_comprehension_nested_plonky3.rs +++ b/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 2; pub const AUX_WIDTH: usize = 0; @@ -53,6 +53,10 @@ impl> AirScriptAir for ListComprehe builder.assert_zero(main_current[0].clone().into() + main_current[1].clone().into().double() - AB::Expr::from_u64(3)); builder.assert_zero(main_current[0].clone().into().double() + main_current[1].clone().into() * AB::Expr::from_u64(3) - AB::Expr::from_u64(5)); builder.assert_zero(main_current[0].clone().into() * AB::Expr::from_u64(3) + main_current[1].clone().into() * AB::Expr::from_u64(4) - AB::Expr::from_u64(7)); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/list_comprehension/list_comprehension_plonky3.rs b/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs similarity index 94% rename from air-script/tests/list_comprehension/list_comprehension_plonky3.rs rename to air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs index 7157d6c28..321df1434 100644 --- a/air-script/tests/list_comprehension/list_comprehension_plonky3.rs +++ b/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 16; pub const AUX_WIDTH: usize = 0; @@ -56,6 +56,10 @@ impl> AirScriptAir for ListComprehe builder.assert_zero(main_current[6].clone().into() - main_current[0].clone().into() * (main_current[9].clone().into() - main_current[14].clone().into())); builder.assert_zero(main_current[1].clone().into() - (main_current[5].clone().into() - main_current[8].clone().into() - main_current[12].clone().into() + AB::Expr::from_u64(10) + main_current[6].clone().into() - main_current[9].clone().into() - main_current[13].clone().into() + AB::Expr::from_u64(20) + main_current[7].clone().into() - main_current[10].clone().into() - main_current[14].clone().into())); builder.assert_zero(main_current[14].clone().into() - AB::Expr::from_u64(10)); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/list_comprehension/mod.rs b/air-script/src/tests/list_comprehension/mod.rs similarity index 100% rename from air-script/tests/list_comprehension/mod.rs rename to air-script/src/tests/list_comprehension/mod.rs diff --git a/air-script/tests/list_comprehension/test_air_plonky3.rs b/air-script/src/tests/list_comprehension/test_air_plonky3.rs similarity index 94% rename from air-script/tests/list_comprehension/test_air_plonky3.rs rename to air-script/src/tests/list_comprehension/test_air_plonky3.rs index d0071c4dc..794c64267 100644 --- a/air-script/tests/list_comprehension/test_air_plonky3.rs +++ b/air-script/src/tests/list_comprehension/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, - list_comprehension::list_comprehension_plonky3::{ListComprehensionAir, MAIN_WIDTH}, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::list_comprehension::list_comprehension_plonky3::{ListComprehensionAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/list_comprehension/test_air_winterfell.rs b/air-script/src/tests/list_comprehension/test_air_winterfell.rs similarity index 87% rename from air-script/tests/list_comprehension/test_air_winterfell.rs rename to air-script/src/tests/list_comprehension/test_air_winterfell.rs index 8fef13b07..749541299 100644 --- a/air-script/tests/list_comprehension/test_air_winterfell.rs +++ b/air-script/src/tests/list_comprehension/test_air_winterfell.rs @@ -4,8 +4,8 @@ use winterfell::{Trace, TraceTable}; use crate::{ generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, - list_comprehension::list_comprehension::PublicInputs, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::list_comprehension::list_comprehension::PublicInputs, }; #[derive(Clone)] @@ -54,7 +54,7 @@ impl AirTester for ListComprehensionAirTester { generate_air_winterfell_test!( test_list_comprehension_air, - crate::list_comprehension::list_comprehension::ListComprehensionAir, + crate::tests::list_comprehension::list_comprehension::ListComprehensionAir, ListComprehensionAirTester, 1024 ); diff --git a/air-script/tests/list_folding/list_folding.air b/air-script/src/tests/list_folding/list_folding.air similarity index 100% rename from air-script/tests/list_folding/list_folding.air rename to air-script/src/tests/list_folding/list_folding.air diff --git a/air-script/tests/list_folding/list_folding.rs b/air-script/src/tests/list_folding/list_folding.rs similarity index 100% rename from air-script/tests/list_folding/list_folding.rs rename to air-script/src/tests/list_folding/list_folding.rs diff --git a/air-script/tests/list_folding/list_folding_plonky3.rs b/air-script/src/tests/list_folding/list_folding_plonky3.rs similarity index 95% rename from air-script/tests/list_folding/list_folding_plonky3.rs rename to air-script/src/tests/list_folding/list_folding_plonky3.rs index bb974c90e..bc2e5add9 100644 --- a/air-script/tests/list_folding/list_folding_plonky3.rs +++ b/air-script/src/tests/list_folding/list_folding_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 17; pub const AUX_WIDTH: usize = 0; @@ -54,6 +54,10 @@ impl> AirScriptAir for ListFoldingA builder.when_transition().assert_zero(main_next[6].clone().into() - (main_current[9].clone().into() + main_current[10].clone().into() + main_current[11].clone().into() + main_current[12].clone().into() + main_current[13].clone().into() * main_current[14].clone().into() * main_current[15].clone().into() * main_current[16].clone().into())); builder.when_transition().assert_zero(main_next[7].clone().into() - (main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + (main_current[9].clone().into() + main_current[13].clone().into()) * (main_current[10].clone().into() + main_current[14].clone().into()) * (main_current[11].clone().into() + main_current[15].clone().into()) * (main_current[12].clone().into() + main_current[16].clone().into()))); builder.when_transition().assert_zero(main_next[8].clone().into() - (main_current[1].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into() + main_current[9].clone().into() * main_current[13].clone().into() + main_current[10].clone().into() * main_current[14].clone().into() + main_current[11].clone().into() * main_current[15].clone().into() + main_current[12].clone().into() * main_current[16].clone().into())); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/list_folding/mod.rs b/air-script/src/tests/list_folding/mod.rs similarity index 100% rename from air-script/tests/list_folding/mod.rs rename to air-script/src/tests/list_folding/mod.rs diff --git a/air-script/tests/list_folding/test_air_plonky3.rs b/air-script/src/tests/list_folding/test_air_plonky3.rs similarity index 95% rename from air-script/tests/list_folding/test_air_plonky3.rs rename to air-script/src/tests/list_folding/test_air_plonky3.rs index 96b89194c..19d3ab9ed 100644 --- a/air-script/tests/list_folding/test_air_plonky3.rs +++ b/air-script/src/tests/list_folding/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, - list_folding::list_folding_plonky3::{ListFoldingAir, MAIN_WIDTH}, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::list_folding::list_folding_plonky3::{ListFoldingAir, MAIN_WIDTH}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/list_folding/test_air_winterfell.rs b/air-script/src/tests/list_folding/test_air_winterfell.rs similarity index 89% rename from air-script/tests/list_folding/test_air_winterfell.rs rename to air-script/src/tests/list_folding/test_air_winterfell.rs index f8376848d..a957f18f9 100644 --- a/air-script/tests/list_folding/test_air_winterfell.rs +++ b/air-script/src/tests/list_folding/test_air_winterfell.rs @@ -4,8 +4,8 @@ use winterfell::{Trace, TraceTable}; use crate::{ generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, - list_folding::list_folding::PublicInputs, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::list_folding::list_folding::PublicInputs, }; #[derive(Clone)] @@ -55,7 +55,7 @@ impl AirTester for ListFoldingAirTester { generate_air_winterfell_test!( test_list_folding_air, - crate::list_folding::list_folding::ListFoldingAir, + crate::tests::list_folding::list_folding::ListFoldingAir, ListFoldingAirTester, 1024 ); diff --git a/air-script/tests/mod.rs b/air-script/src/tests/mod.rs similarity index 97% rename from air-script/tests/mod.rs rename to air-script/src/tests/mod.rs index 1f8c0fc09..c3d85e7a0 100644 --- a/air-script/tests/mod.rs +++ b/air-script/src/tests/mod.rs @@ -1,7 +1,3 @@ -mod codegen; - -pub mod helpers; - #[allow(unused_variables, dead_code, unused_mut)] mod binary; #[allow(unused_variables, dead_code, unused_mut)] @@ -42,3 +38,5 @@ mod trace_col_groups; mod variables; mod docs_sync; +mod plonky3; +mod winterfell; diff --git a/air-script/tests/periodic_columns/mod.rs b/air-script/src/tests/periodic_columns/mod.rs similarity index 100% rename from air-script/tests/periodic_columns/mod.rs rename to air-script/src/tests/periodic_columns/mod.rs diff --git a/air-script/tests/periodic_columns/periodic_columns.air b/air-script/src/tests/periodic_columns/periodic_columns.air similarity index 100% rename from air-script/tests/periodic_columns/periodic_columns.air rename to air-script/src/tests/periodic_columns/periodic_columns.air diff --git a/air-script/tests/periodic_columns/periodic_columns.rs b/air-script/src/tests/periodic_columns/periodic_columns.rs similarity index 100% rename from air-script/tests/periodic_columns/periodic_columns.rs rename to air-script/src/tests/periodic_columns/periodic_columns.rs diff --git a/air-script/tests/periodic_columns/periodic_columns_plonky3.rs b/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs similarity index 93% rename from air-script/tests/periodic_columns/periodic_columns_plonky3.rs rename to air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs index 32c6fbcd0..766e8777a 100644 --- a/air-script/tests/periodic_columns/periodic_columns_plonky3.rs +++ b/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 3; pub const AUX_WIDTH: usize = 0; @@ -55,6 +55,10 @@ impl> AirScriptAir for PeriodicColu // Main integrity/transition constraints builder.assert_zero_ext(periodic_values[0].into() * (AB::ExprEF::from(main_current[1].clone().into()) + AB::ExprEF::from(main_current[2].clone().into()))); builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/periodic_columns/test_air_plonky3.rs b/air-script/src/tests/periodic_columns/test_air_plonky3.rs similarity index 91% rename from air-script/tests/periodic_columns/test_air_plonky3.rs rename to air-script/src/tests/periodic_columns/test_air_plonky3.rs index 7342c8296..fc3724624 100644 --- a/air-script/tests/periodic_columns/test_air_plonky3.rs +++ b/air-script/src/tests/periodic_columns/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, - periodic_columns::periodic_columns_plonky3::{MAIN_WIDTH, PeriodicColumnsAir}, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::periodic_columns::periodic_columns_plonky3::{MAIN_WIDTH, PeriodicColumnsAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/periodic_columns/test_air_winterfell.rs b/air-script/src/tests/periodic_columns/test_air_winterfell.rs similarity index 82% rename from air-script/tests/periodic_columns/test_air_winterfell.rs rename to air-script/src/tests/periodic_columns/test_air_winterfell.rs index 0adc8364f..cf92e1101 100644 --- a/air-script/tests/periodic_columns/test_air_winterfell.rs +++ b/air-script/src/tests/periodic_columns/test_air_winterfell.rs @@ -4,8 +4,8 @@ use winterfell::{Trace, TraceTable}; use crate::{ generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, - periodic_columns::periodic_columns::PublicInputs, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::periodic_columns::periodic_columns::PublicInputs, }; #[derive(Clone)] @@ -39,7 +39,7 @@ impl AirTester for PeriodicColumnsAirTester { generate_air_winterfell_test!( test_periodic_columns_air, - crate::periodic_columns::periodic_columns::PeriodicColumnsAir, + crate::tests::periodic_columns::periodic_columns::PeriodicColumnsAir, PeriodicColumnsAirTester, 1024 ); diff --git a/air-script/src/tests/plonky3.rs b/air-script/src/tests/plonky3.rs new file mode 100644 index 000000000..71c5c2c87 --- /dev/null +++ b/air-script/src/tests/plonky3.rs @@ -0,0 +1,333 @@ +use expect_test::expect_file; + +use crate::test_utils::codegen::{Target, Test}; + +#[test] +fn binary() { + let generated_air = Test::new("src/tests/binary/binary.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["binary/binary_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn bitwise() { + let generated_air = Test::new("src/tests/bitwise/bitwise.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["bitwise/bitwise_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_complex() { + let generated_air = Test::new("src/tests/buses/buses_complex.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["buses/buses_complex_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_simple() { + let generated_air = Test::new("src/tests/buses/buses_simple.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["buses/buses_simple_plonky3.rs"]; + expected.assert_eq(&generated_air); +} +#[test] +fn buses_simple_with_evaluators() { + let generated_air = Test::new("src/tests/buses/buses_simple_with_evaluators.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["buses/buses_simple_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_varlen_boundary_both() { + let generated_air = Test::new("src/tests/buses/buses_varlen_boundary_both.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["buses/buses_varlen_boundary_both_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_varlen_boundary_first() { + let generated_air = Test::new("src/tests/buses/buses_varlen_boundary_first.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["buses/buses_varlen_boundary_first_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_varlen_boundary_last() { + let generated_air = Test::new("src/tests/buses/buses_varlen_boundary_last.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["buses/buses_varlen_boundary_last_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn computed_indices_complex() { + let generated_air = + Test::new("src/tests/computed_indices/computed_indices_complex.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["computed_indices/computed_indices_complex_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn computed_indices_simple() { + let generated_air = Test::new("src/tests/computed_indices/computed_indices_simple.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["computed_indices/computed_indices_simple_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn constant_in_range() { + let generated_air = Test::new("src/tests/constant_in_range/constant_in_range.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["constant_in_range/constant_in_range_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn constants() { + let generated_air = Test::new("src/tests/constants/constants.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["constants/constants_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn evaluators() { + let generated_air = Test::new("src/tests/evaluators/evaluators.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["evaluators/evaluators_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn fibonacci() { + let generated_air = Test::new("src/tests/fibonacci/fibonacci.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["fibonacci/fibonacci_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn functions_complex() { + let generated_air = Test::new("src/tests/functions/functions_complex.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["functions/functions_complex_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn functions_simple() { + let generated_air = Test::new("src/tests/functions/functions_simple.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["functions/functions_simple_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn functions_simple_inlined() { + // make sure that the constraints generated using inlined functions are the same as the ones + // generated using regular functions + let generated_air = Test::new("src/tests/functions/inlined_functions_simple.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["functions/functions_simple_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn indexed_trace_access() { + let generated_air = + Test::new("src/tests/indexed_trace_access/indexed_trace_access.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["indexed_trace_access/indexed_trace_access_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn list_comprehension_nested() { + let generated_air = + Test::new("src/tests/list_comprehension/list_comprehension_nested.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["list_comprehension/list_comprehension_nested_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn list_comprehension() { + let generated_air = Test::new("src/tests/list_comprehension/list_comprehension.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["list_comprehension/list_comprehension_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn list_folding() { + let generated_air = Test::new("src/tests/list_folding/list_folding.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["list_folding/list_folding_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn periodic_columns() { + let generated_air = Test::new("src/tests/periodic_columns/periodic_columns.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["periodic_columns/periodic_columns_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn pub_inputs() { + let generated_air = Test::new("src/tests/pub_inputs/pub_inputs.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["pub_inputs/pub_inputs_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn selectors_combine_complex() { + let generated_air = Test::new("src/tests/selectors/selectors_combine_complex.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["selectors/selectors_combine_complex_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn selectors_combine_simple() { + let generated_air = Test::new("src/tests/selectors/selectors_combine_simple.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["selectors/selectors_combine_simple_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn selectors_combine_with_list_comprehensions() { + let generated_air = Test::new("src/tests/selectors/selectors_combine_with_list_comprehensions.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["selectors/selectors_combine_with_list_comprehensions_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn selectors() { + let generated_air = Test::new("src/tests/selectors/selectors.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["selectors/selectors_plonky3.rs"]; + expected.assert_eq(&generated_air); + + let generated_air = Test::new("src/tests/selectors/selectors_with_evaluators.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["selectors/selectors_with_evaluators_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn system() { + let generated_air = Test::new("src/tests/system/system.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["system/system_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn trace_col_groups() { + let generated_air = Test::new("src/tests/trace_col_groups/trace_col_groups.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["trace_col_groups/trace_col_groups_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn variables() { + let generated_air = Test::new("src/tests/variables/variables.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["variables/variables_plonky3.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn constraint_comprehension() { + let generated_air = + Test::new("src/tests/constraint_comprehension/constraint_comprehension.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["constraint_comprehension/constraint_comprehension_plonky3.rs"]; + expected.assert_eq(&generated_air); + + let generated_air = + Test::new("src/tests/constraint_comprehension/cc_with_evaluators.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); + + let expected = expect_file!["constraint_comprehension/constraint_comprehension_plonky3.rs"]; + expected.assert_eq(&generated_air); +} diff --git a/air-script/tests/pub_inputs/mod.rs b/air-script/src/tests/pub_inputs/mod.rs similarity index 100% rename from air-script/tests/pub_inputs/mod.rs rename to air-script/src/tests/pub_inputs/mod.rs diff --git a/air-script/tests/pub_inputs/pub_inputs.air b/air-script/src/tests/pub_inputs/pub_inputs.air similarity index 100% rename from air-script/tests/pub_inputs/pub_inputs.air rename to air-script/src/tests/pub_inputs/pub_inputs.air diff --git a/air-script/tests/pub_inputs/pub_inputs.rs b/air-script/src/tests/pub_inputs/pub_inputs.rs similarity index 100% rename from air-script/tests/pub_inputs/pub_inputs.rs rename to air-script/src/tests/pub_inputs/pub_inputs.rs diff --git a/air-script/tests/pub_inputs/pub_inputs_plonky3.rs b/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs similarity index 94% rename from air-script/tests/pub_inputs/pub_inputs_plonky3.rs rename to air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs index c5c01e5af..2e71940bd 100644 --- a/air-script/tests/pub_inputs/pub_inputs_plonky3.rs +++ b/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -58,6 +58,10 @@ impl> AirScriptAir for PubInputsAir // Main integrity/transition constraints builder.when_transition().assert_zero(main_next[0].clone().into() - (main_current[1].clone().into() + main_current[2].clone().into())); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/pub_inputs/test_air_plonky3.rs b/air-script/src/tests/pub_inputs/test_air_plonky3.rs similarity index 92% rename from air-script/tests/pub_inputs/test_air_plonky3.rs rename to air-script/src/tests/pub_inputs/test_air_plonky3.rs index 87d39db5a..742078244 100644 --- a/air-script/tests/pub_inputs/test_air_plonky3.rs +++ b/air-script/src/tests/pub_inputs/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, - pub_inputs::pub_inputs_plonky3::{MAIN_WIDTH, PubInputsAir}, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::pub_inputs::pub_inputs_plonky3::{MAIN_WIDTH, PubInputsAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/pub_inputs/test_air_winterfell.rs b/air-script/src/tests/pub_inputs/test_air_winterfell.rs similarity index 85% rename from air-script/tests/pub_inputs/test_air_winterfell.rs rename to air-script/src/tests/pub_inputs/test_air_winterfell.rs index 947f4bbac..62b8be849 100644 --- a/air-script/tests/pub_inputs/test_air_winterfell.rs +++ b/air-script/src/tests/pub_inputs/test_air_winterfell.rs @@ -4,8 +4,8 @@ use winterfell::{Trace, TraceTable}; use crate::{ generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, - pub_inputs::pub_inputs::PublicInputs, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::pub_inputs::pub_inputs::PublicInputs, }; #[derive(Clone)] @@ -40,7 +40,7 @@ impl AirTester for PubInputsAirTester { generate_air_winterfell_test!( test_pub_inputs_air, - crate::pub_inputs::pub_inputs::PubInputsAir, + crate::tests::pub_inputs::pub_inputs::PubInputsAir, PubInputsAirTester, 1024 ); diff --git a/air-script/tests/selectors/mod.rs b/air-script/src/tests/selectors/mod.rs similarity index 100% rename from air-script/tests/selectors/mod.rs rename to air-script/src/tests/selectors/mod.rs diff --git a/air-script/tests/selectors/selectors.air b/air-script/src/tests/selectors/selectors.air similarity index 100% rename from air-script/tests/selectors/selectors.air rename to air-script/src/tests/selectors/selectors.air diff --git a/air-script/tests/selectors/selectors.rs b/air-script/src/tests/selectors/selectors.rs similarity index 100% rename from air-script/tests/selectors/selectors.rs rename to air-script/src/tests/selectors/selectors.rs diff --git a/air-script/tests/selectors/selectors_combine_complex.air b/air-script/src/tests/selectors/selectors_combine_complex.air similarity index 100% rename from air-script/tests/selectors/selectors_combine_complex.air rename to air-script/src/tests/selectors/selectors_combine_complex.air diff --git a/air-script/tests/selectors/selectors_combine_complex.rs b/air-script/src/tests/selectors/selectors_combine_complex.rs similarity index 100% rename from air-script/tests/selectors/selectors_combine_complex.rs rename to air-script/src/tests/selectors/selectors_combine_complex.rs diff --git a/air-script/tests/selectors/selectors_combine_complex_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs similarity index 98% rename from air-script/tests/selectors/selectors_combine_complex_plonky3.rs rename to air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs index 4d0ab6a34..c13d91769 100644 --- a/air-script/tests/selectors/selectors_combine_complex_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 6; pub const AUX_WIDTH: usize = 1; diff --git a/air-script/tests/selectors/selectors_combine_simple.air b/air-script/src/tests/selectors/selectors_combine_simple.air similarity index 100% rename from air-script/tests/selectors/selectors_combine_simple.air rename to air-script/src/tests/selectors/selectors_combine_simple.air diff --git a/air-script/tests/selectors/selectors_combine_simple.rs b/air-script/src/tests/selectors/selectors_combine_simple.rs similarity index 100% rename from air-script/tests/selectors/selectors_combine_simple.rs rename to air-script/src/tests/selectors/selectors_combine_simple.rs diff --git a/air-script/tests/selectors/selectors_combine_simple_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs similarity index 93% rename from air-script/tests/selectors/selectors_combine_simple_plonky3.rs rename to air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs index 50b2cda0d..31550cd79 100644 --- a/air-script/tests/selectors/selectors_combine_simple_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -52,6 +52,10 @@ impl> AirScriptAir for SelectorsAir // Main integrity/transition constraints builder.when_transition().assert_zero(main_next[1].clone().into() - main_current[2].clone().into()); builder.when_transition().assert_zero(main_current[3].clone().into() * (main_next[0].clone().into() - (main_current[0].clone().into() + main_current[1].clone().into())) + (AB::Expr::ONE - main_current[3].clone().into()) * (main_next[0].clone().into() - main_current[0].clone().into() * main_current[1].clone().into())); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/selectors/selectors_combine_with_list_comprehensions.air b/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions.air similarity index 100% rename from air-script/tests/selectors/selectors_combine_with_list_comprehensions.air rename to air-script/src/tests/selectors/selectors_combine_with_list_comprehensions.air diff --git a/air-script/tests/selectors/selectors_combine_with_list_comprehensions.rs b/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions.rs similarity index 100% rename from air-script/tests/selectors/selectors_combine_with_list_comprehensions.rs rename to air-script/src/tests/selectors/selectors_combine_with_list_comprehensions.rs diff --git a/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs similarity index 94% rename from air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs rename to air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs index 5cc70b27a..06cb94909 100644 --- a/air-script/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 6; pub const AUX_WIDTH: usize = 0; @@ -53,6 +53,10 @@ impl> AirScriptAir for SelectorsAir builder.assert_zero((main_current[0].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into()) * main_current[3].clone().into() + (AB::Expr::ONE - main_current[0].clone().into()) * (AB::Expr::ONE - main_current[1].clone().into()) * (main_current[4].clone().into() - AB::Expr::from_u64(8))); builder.assert_zero((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[5].clone().into() - AB::Expr::from_u64(8)) + main_current[0].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(2))); builder.assert_zero(main_current[0].clone().into() * (main_current[5].clone().into() - AB::Expr::from_u64(4)) + (AB::Expr::ONE - main_current[0].clone().into()) * main_current[1].clone().into() * (main_current[4].clone().into() - AB::Expr::from_u64(6))); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/selectors/selectors_plonky3.rs b/air-script/src/tests/selectors/selectors_plonky3.rs similarity index 93% rename from air-script/tests/selectors/selectors_plonky3.rs rename to air-script/src/tests/selectors/selectors_plonky3.rs index a0d6c8bee..0a1ac04d0 100644 --- a/air-script/tests/selectors/selectors_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -52,6 +52,10 @@ impl> AirScriptAir for SelectorsAir // Main integrity/transition constraints builder.when_transition().assert_zero(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); builder.when_transition().assert_zero(main_current[0].clone().into() * main_current[1].clone().into() * main_current[2].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/selectors/selectors_with_evaluators.air b/air-script/src/tests/selectors/selectors_with_evaluators.air similarity index 100% rename from air-script/tests/selectors/selectors_with_evaluators.air rename to air-script/src/tests/selectors/selectors_with_evaluators.air diff --git a/air-script/tests/selectors/selectors_with_evaluators.rs b/air-script/src/tests/selectors/selectors_with_evaluators.rs similarity index 100% rename from air-script/tests/selectors/selectors_with_evaluators.rs rename to air-script/src/tests/selectors/selectors_with_evaluators.rs diff --git a/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs b/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs similarity index 93% rename from air-script/tests/selectors/selectors_with_evaluators_plonky3.rs rename to air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs index 82bbc21c8..38fb17709 100644 --- a/air-script/tests/selectors/selectors_with_evaluators_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -52,6 +52,10 @@ impl> AirScriptAir for SelectorsAir // Main integrity/transition constraints builder.when_transition().assert_zero(main_current[0].clone().into() * (AB::Expr::ONE - main_current[1].clone().into()) * main_next[3].clone().into()); builder.when_transition().assert_zero(main_current[1].clone().into() * main_current[2].clone().into() * main_current[0].clone().into() * (main_next[3].clone().into() - main_current[3].clone().into()) + (AB::Expr::ONE - main_current[1].clone().into()) * (AB::Expr::ONE - main_current[2].clone().into()) * (main_next[3].clone().into() - AB::Expr::ONE)); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/selectors/test_air_plonky3.rs b/air-script/src/tests/selectors/test_air_plonky3.rs similarity index 92% rename from air-script/tests/selectors/test_air_plonky3.rs rename to air-script/src/tests/selectors/test_air_plonky3.rs index 4a05ee0c9..3c5688ed1 100644 --- a/air-script/tests/selectors/test_air_plonky3.rs +++ b/air-script/src/tests/selectors/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, - selectors::selectors_with_evaluators_plonky3::{MAIN_WIDTH, SelectorsAir}, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::selectors::selectors_with_evaluators_plonky3::{MAIN_WIDTH, SelectorsAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/selectors/test_air_winterfell.rs b/air-script/src/tests/selectors/test_air_winterfell.rs similarity index 84% rename from air-script/tests/selectors/test_air_winterfell.rs rename to air-script/src/tests/selectors/test_air_winterfell.rs index 19f683ef6..3bb3ac337 100644 --- a/air-script/tests/selectors/test_air_winterfell.rs +++ b/air-script/src/tests/selectors/test_air_winterfell.rs @@ -4,8 +4,8 @@ use winterfell::{Trace, TraceTable}; use crate::{ generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, - selectors::selectors_with_evaluators::PublicInputs, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::selectors::selectors_with_evaluators::PublicInputs, }; #[derive(Clone)] @@ -42,7 +42,7 @@ impl AirTester for SelectorsAirTester { generate_air_winterfell_test!( test_selectors_with_evaluators_air, - crate::selectors::selectors_with_evaluators::SelectorsAir, + crate::tests::selectors::selectors_with_evaluators::SelectorsAir, SelectorsAirTester, 1024 ); diff --git a/air-script/tests/system/mod.rs b/air-script/src/tests/system/mod.rs similarity index 100% rename from air-script/tests/system/mod.rs rename to air-script/src/tests/system/mod.rs diff --git a/air-script/tests/system/system.air b/air-script/src/tests/system/system.air similarity index 100% rename from air-script/tests/system/system.air rename to air-script/src/tests/system/system.air diff --git a/air-script/tests/system/system.rs b/air-script/src/tests/system/system.rs similarity index 100% rename from air-script/tests/system/system.rs rename to air-script/src/tests/system/system.rs diff --git a/air-script/tests/system/system_plonky3.rs b/air-script/src/tests/system/system_plonky3.rs similarity index 92% rename from air-script/tests/system/system_plonky3.rs rename to air-script/src/tests/system/system_plonky3.rs index a6eaad01b..5eed1e2c0 100644 --- a/air-script/tests/system/system_plonky3.rs +++ b/air-script/src/tests/system/system_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 3; pub const AUX_WIDTH: usize = 0; @@ -51,6 +51,10 @@ impl> AirScriptAir for SystemAir { // Main integrity/transition constraints builder.when_transition().assert_zero(main_next[0].clone().into() - (main_current[0].clone().into() + AB::Expr::ONE)); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/system/test_air_plonky3.rs b/air-script/src/tests/system/test_air_plonky3.rs similarity index 92% rename from air-script/tests/system/test_air_plonky3.rs rename to air-script/src/tests/system/test_air_plonky3.rs index 45e6ca693..969ce7f4e 100644 --- a/air-script/tests/system/test_air_plonky3.rs +++ b/air-script/src/tests/system/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, - system::system_plonky3::{MAIN_WIDTH, SystemAir}, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::system::system_plonky3::{MAIN_WIDTH, SystemAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/system/test_air_winterfell.rs b/air-script/src/tests/system/test_air_winterfell.rs similarity index 86% rename from air-script/tests/system/test_air_winterfell.rs rename to air-script/src/tests/system/test_air_winterfell.rs index 9327f6e98..99a717f78 100644 --- a/air-script/tests/system/test_air_winterfell.rs +++ b/air-script/src/tests/system/test_air_winterfell.rs @@ -4,8 +4,8 @@ use winterfell::{Trace, TraceTable}; use crate::{ generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, - system::system::PublicInputs, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::system::system::PublicInputs, }; #[derive(Clone)] @@ -41,7 +41,7 @@ impl AirTester for SystemAirTester { generate_air_winterfell_test!( test_system_air, - crate::system::system::SystemAir, + crate::tests::system::system::SystemAir, SystemAirTester, 1024 ); diff --git a/air-script/tests/trace_col_groups/mod.rs b/air-script/src/tests/trace_col_groups/mod.rs similarity index 100% rename from air-script/tests/trace_col_groups/mod.rs rename to air-script/src/tests/trace_col_groups/mod.rs diff --git a/air-script/tests/trace_col_groups/test_air_plonky3.rs b/air-script/src/tests/trace_col_groups/test_air_plonky3.rs similarity index 93% rename from air-script/tests/trace_col_groups/test_air_plonky3.rs rename to air-script/src/tests/trace_col_groups/test_air_plonky3.rs index de115e6e3..9c059df19 100644 --- a/air-script/tests/trace_col_groups/test_air_plonky3.rs +++ b/air-script/src/tests/trace_col_groups/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, - trace_col_groups::trace_col_groups_plonky3::{MAIN_WIDTH, TraceColGroupAir}, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::trace_col_groups::trace_col_groups_plonky3::{MAIN_WIDTH, TraceColGroupAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/trace_col_groups/test_air_winterfell.rs b/air-script/src/tests/trace_col_groups/test_air_winterfell.rs similarity index 86% rename from air-script/tests/trace_col_groups/test_air_winterfell.rs rename to air-script/src/tests/trace_col_groups/test_air_winterfell.rs index 92400a4f2..53a5af721 100644 --- a/air-script/tests/trace_col_groups/test_air_winterfell.rs +++ b/air-script/src/tests/trace_col_groups/test_air_winterfell.rs @@ -4,8 +4,8 @@ use winterfell::{Trace, TraceTable}; use crate::{ generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, - trace_col_groups::trace_col_groups::PublicInputs, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::trace_col_groups::trace_col_groups::PublicInputs, }; #[derive(Clone)] @@ -48,7 +48,7 @@ impl AirTester for TraceColGroupAirTester { generate_air_winterfell_test!( test_trace_col_groups_air, - crate::trace_col_groups::trace_col_groups::TraceColGroupAir, + crate::tests::trace_col_groups::trace_col_groups::TraceColGroupAir, TraceColGroupAirTester, 1024 ); diff --git a/air-script/tests/trace_col_groups/trace_col_groups.air b/air-script/src/tests/trace_col_groups/trace_col_groups.air similarity index 100% rename from air-script/tests/trace_col_groups/trace_col_groups.air rename to air-script/src/tests/trace_col_groups/trace_col_groups.air diff --git a/air-script/tests/trace_col_groups/trace_col_groups.rs b/air-script/src/tests/trace_col_groups/trace_col_groups.rs similarity index 100% rename from air-script/tests/trace_col_groups/trace_col_groups.rs rename to air-script/src/tests/trace_col_groups/trace_col_groups.rs diff --git a/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs b/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs similarity index 92% rename from air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs rename to air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs index cb01541fa..10154bb14 100644 --- a/air-script/tests/trace_col_groups/trace_col_groups_plonky3.rs +++ b/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 9; pub const AUX_WIDTH: usize = 0; @@ -52,6 +52,10 @@ impl> AirScriptAir for TraceColGrou // Main integrity/transition constraints builder.when_transition().assert_zero(main_next[2].clone().into() - (main_current[2].clone().into() + AB::Expr::ONE)); builder.when_transition().assert_zero(main_next[1].clone().into() - (main_current[1].clone().into() - AB::Expr::ONE)); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/tests/variables/mod.rs b/air-script/src/tests/variables/mod.rs similarity index 100% rename from air-script/tests/variables/mod.rs rename to air-script/src/tests/variables/mod.rs diff --git a/air-script/tests/variables/test_air_plonky3.rs b/air-script/src/tests/variables/test_air_plonky3.rs similarity index 92% rename from air-script/tests/variables/test_air_plonky3.rs rename to air-script/src/tests/variables/test_air_plonky3.rs index a008fe31e..3509c6925 100644 --- a/air-script/tests/variables/test_air_plonky3.rs +++ b/air-script/src/tests/variables/test_air_plonky3.rs @@ -14,8 +14,8 @@ use p3_uni_stark::StarkConfig; use crate::{ generate_air_plonky3_test_with_airscript_traits, - helpers::check_constraints_with_airscript_traits, - variables::variables_plonky3::{MAIN_WIDTH, VariablesAir}, + test_utils::plonky3_traits::check_constraints_with_airscript_traits, + tests::variables::variables_plonky3::{MAIN_WIDTH, VariablesAir}, }; pub fn generate_trace_rows(inputs: Vec) -> RowMajorMatrix { diff --git a/air-script/tests/variables/test_air_winterfell.rs b/air-script/src/tests/variables/test_air_winterfell.rs similarity index 86% rename from air-script/tests/variables/test_air_winterfell.rs rename to air-script/src/tests/variables/test_air_winterfell.rs index 3578f330f..d384975b3 100644 --- a/air-script/tests/variables/test_air_winterfell.rs +++ b/air-script/src/tests/variables/test_air_winterfell.rs @@ -4,8 +4,8 @@ use winterfell::{Trace, TraceTable}; use crate::{ generate_air_winterfell_test, - helpers::{AirTester, MyTraceTable}, - variables::variables::PublicInputs, + test_utils::winterfell_traits::{AirTester, MyTraceTable}, + tests::variables::variables::PublicInputs, }; #[derive(Clone)] @@ -42,7 +42,7 @@ impl AirTester for VariablesAirTester { generate_air_winterfell_test!( test_variables_air, - crate::variables::variables::VariablesAir, + crate::tests::variables::variables::VariablesAir, VariablesAirTester, 1024 ); diff --git a/air-script/tests/variables/variables.air b/air-script/src/tests/variables/variables.air similarity index 100% rename from air-script/tests/variables/variables.air rename to air-script/src/tests/variables/variables.air diff --git a/air-script/tests/variables/variables.rs b/air-script/src/tests/variables/variables.rs similarity index 100% rename from air-script/tests/variables/variables.rs rename to air-script/src/tests/variables/variables.rs diff --git a/air-script/tests/variables/variables_plonky3.rs b/air-script/src/tests/variables/variables_plonky3.rs similarity index 94% rename from air-script/tests/variables/variables_plonky3.rs rename to air-script/src/tests/variables/variables_plonky3.rs index 0f0da0331..ea20548c9 100644 --- a/air-script/tests/variables/variables_plonky3.rs +++ b/air-script/src/tests/variables/variables_plonky3.rs @@ -1,7 +1,7 @@ use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; use p3_matrix::Matrix; use p3_field::{Field, PrimeCharacteristicRing}; -use crate::helpers::{AirScriptAir, AirScriptBuilder}; +use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -57,6 +57,10 @@ impl> AirScriptAir for VariablesAir builder.when_transition().assert_zero_ext(periodic_values[0].into() * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); builder.assert_zero((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[3].clone().into() - main_current[1].clone().into() - main_current[2].clone().into()) - (AB::Expr::from_u64(6) - (AB::Expr::from_u64(7) - main_current[0].clone().into()))); builder.when_transition().assert_zero(main_current[0].clone().into() * (main_current[3].clone().into() - main_current[1].clone().into() * main_current[2].clone().into()) - (AB::Expr::ONE - main_next[0].clone().into())); + + // Aux boundary constraints + + // Aux integrity/transition constraints } } diff --git a/air-script/src/tests/winterfell.rs b/air-script/src/tests/winterfell.rs new file mode 100644 index 000000000..a63eff87d --- /dev/null +++ b/air-script/src/tests/winterfell.rs @@ -0,0 +1,335 @@ +use expect_test::expect_file; + +use crate::test_utils::codegen::{Target, Test}; + +#[test] +fn binary() { + let generated_air = Test::new("src/tests/binary/binary.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["binary/binary.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn bitwise() { + let generated_air = Test::new("src/tests/bitwise/bitwise.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["bitwise/bitwise.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_complex() { + let generated_air = Test::new("src/tests/buses/buses_complex.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["buses/buses_complex.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_simple() { + let generated_air = Test::new("src/tests/buses/buses_simple.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["buses/buses_simple.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_simple_with_evaluators() { + let generated_air = Test::new("src/tests/buses/buses_simple_with_evaluators.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["buses/buses_simple.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_varlen_boundary_both() { + let generated_air = Test::new("src/tests/buses/buses_varlen_boundary_both.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["buses/buses_varlen_boundary_both.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_varlen_boundary_first() { + let generated_air = Test::new("src/tests/buses/buses_varlen_boundary_first.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["buses/buses_varlen_boundary_first.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn buses_varlen_boundary_last() { + let generated_air = Test::new("src/tests/buses/buses_varlen_boundary_last.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["buses/buses_varlen_boundary_last.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn computed_indices_complex() { + let generated_air = + Test::new("src/tests/computed_indices/computed_indices_complex.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["computed_indices/computed_indices_complex.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn computed_indices_simple() { + let generated_air = Test::new("src/tests/computed_indices/computed_indices_simple.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["computed_indices/computed_indices_simple.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn constant_in_range() { + let generated_air = Test::new("src/tests/constant_in_range/constant_in_range.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["constant_in_range/constant_in_range.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn constants() { + let generated_air = Test::new("src/tests/constants/constants.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["constants/constants.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn constraint_comprehension() { + let generated_air = + Test::new("src/tests/constraint_comprehension/constraint_comprehension.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["constraint_comprehension/constraint_comprehension.rs"]; + expected.assert_eq(&generated_air); + + let generated_air = + Test::new("src/tests/constraint_comprehension/cc_with_evaluators.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["constraint_comprehension/constraint_comprehension.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn evaluators() { + let generated_air = Test::new("src/tests/evaluators/evaluators.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["evaluators/evaluators.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn fibonacci() { + let generated_air = Test::new("src/tests/fibonacci/fibonacci.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["fibonacci/fibonacci.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn functions_complex() { + let generated_air = Test::new("src/tests/functions/functions_complex.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["functions/functions_complex.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn functions_simple() { + let generated_air = Test::new("src/tests/functions/functions_simple.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["functions/functions_simple.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn functions_simple_inlined() { + // make sure that the constraints generated using inlined functions are the same as the ones + // generated using regular functions + let generated_air = Test::new("src/tests/functions/inlined_functions_simple.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["functions/functions_simple.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn indexed_trace_access() { + let generated_air = + Test::new("src/tests/indexed_trace_access/indexed_trace_access.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["indexed_trace_access/indexed_trace_access.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn list_comprehension() { + let generated_air = Test::new("src/tests/list_comprehension/list_comprehension.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["list_comprehension/list_comprehension.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn list_comprehension_nested() { + let generated_air = + Test::new("src/tests/list_comprehension/list_comprehension_nested.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["list_comprehension/list_comprehension_nested.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn list_folding() { + let generated_air = Test::new("src/tests/list_folding/list_folding.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["list_folding/list_folding.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn periodic_columns() { + let generated_air = Test::new("src/tests/periodic_columns/periodic_columns.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["periodic_columns/periodic_columns.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn pub_inputs() { + let generated_air = Test::new("src/tests/pub_inputs/pub_inputs.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["pub_inputs/pub_inputs.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn selectors() { + let generated_air = Test::new("src/tests/selectors/selectors.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["selectors/selectors.rs"]; + expected.assert_eq(&generated_air); + + let generated_air = Test::new("src/tests/selectors/selectors_with_evaluators.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["selectors/selectors_with_evaluators.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn selectors_combine_simple() { + let generated_air = Test::new("src/tests/selectors/selectors_combine_simple.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["selectors/selectors_combine_simple.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn selectors_combine_complex() { + let generated_air = Test::new("src/tests/selectors/selectors_combine_complex.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["selectors/selectors_combine_complex.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn selectors_combine_with_list_comprehensions() { + let generated_air = + Test::new("src/tests/selectors/selectors_combine_with_list_comprehensions.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["selectors/selectors_combine_with_list_comprehensions.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn system() { + let generated_air = Test::new("src/tests/system/system.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["system/system.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn trace_col_groups() { + let generated_air = Test::new("src/tests/trace_col_groups/trace_col_groups.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["trace_col_groups/trace_col_groups.rs"]; + expected.assert_eq(&generated_air); +} + +#[test] +fn variables() { + let generated_air = Test::new("src/tests/variables/variables.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); + + let expected = expect_file!["variables/variables.rs"]; + expected.assert_eq(&generated_air); +} diff --git a/air-script/tests/codegen/mod.rs b/air-script/tests/codegen/mod.rs deleted file mode 100644 index a23676b61..000000000 --- a/air-script/tests/codegen/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -mod helpers; -mod plonky3; -mod winterfell; diff --git a/air-script/tests/codegen/plonky3.rs b/air-script/tests/codegen/plonky3.rs deleted file mode 100644 index 8ccbb2d55..000000000 --- a/air-script/tests/codegen/plonky3.rs +++ /dev/null @@ -1,323 +0,0 @@ -use expect_test::expect_file; - -use super::helpers::{Target, Test}; - -#[test] -fn binary() { - let generated_air = Test::new("tests/binary/binary.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../binary/binary_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_simple() { - let generated_air = Test::new("tests/buses/buses_simple.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../buses/buses_simple_plonky3.rs"]; - expected.assert_eq(&generated_air); -} -#[test] -fn buses_simple_with_evaluators() { - let generated_air = Test::new("tests/buses/buses_simple_with_evaluators.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../buses/buses_simple_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_complex() { - let generated_air = Test::new("tests/buses/buses_complex.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../buses/buses_complex_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_varlen_boundary_first() { - let generated_air = Test::new("tests/buses/buses_varlen_boundary_first.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../buses/buses_varlen_boundary_first_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_varlen_boundary_last() { - let generated_air = Test::new("tests/buses/buses_varlen_boundary_last.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../buses/buses_varlen_boundary_last_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_varlen_boundary_both() { - let generated_air = Test::new("tests/buses/buses_varlen_boundary_both.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../buses/buses_varlen_boundary_both_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn periodic_columns() { - let generated_air = Test::new("tests/periodic_columns/periodic_columns.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../periodic_columns/periodic_columns_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn pub_inputs() { - let generated_air = Test::new("tests/pub_inputs/pub_inputs.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../pub_inputs/pub_inputs_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn system() { - let generated_air = Test::new("tests/system/system.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../system/system_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn bitwise() { - let generated_air = Test::new("tests/bitwise/bitwise.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../bitwise/bitwise_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn computed_indices_complex() { - let generated_air = - Test::new("tests/computed_indices/computed_indices_complex.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../computed_indices/computed_indices_complex_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn computed_indices_simple() { - let generated_air = Test::new("tests/computed_indices/computed_indices_simple.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../computed_indices/computed_indices_simple_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn constants() { - let generated_air = Test::new("tests/constants/constants.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../constants/constants_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn constant_in_range() { - let generated_air = Test::new("tests/constant_in_range/constant_in_range.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../constant_in_range/constant_in_range_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn evaluators() { - let generated_air = Test::new("tests/evaluators/evaluators.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../evaluators/evaluators_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn fibonacci() { - let generated_air = Test::new("tests/fibonacci/fibonacci.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../fibonacci/fibonacci_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn functions_simple() { - let generated_air = Test::new("tests/functions/functions_simple.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../functions/functions_simple_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn functions_simple_inlined() { - // make sure that the constraints generated using inlined functions are the same as the ones - // generated using regular functions - let generated_air = Test::new("tests/functions/inlined_functions_simple.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../functions/functions_simple_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn functions_complex() { - let generated_air = Test::new("tests/functions/functions_complex.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../functions/functions_complex_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn variables() { - let generated_air = Test::new("tests/variables/variables.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../variables/variables_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn trace_col_groups() { - let generated_air = Test::new("tests/trace_col_groups/trace_col_groups.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../trace_col_groups/trace_col_groups_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn indexed_trace_access() { - let generated_air = - Test::new("tests/indexed_trace_access/indexed_trace_access.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../indexed_trace_access/indexed_trace_access_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn list_comprehension() { - let generated_air = Test::new("tests/list_comprehension/list_comprehension.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../list_comprehension/list_comprehension_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn list_comprehension_nested() { - let generated_air = - Test::new("tests/list_comprehension/list_comprehension_nested.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../list_comprehension/list_comprehension_nested_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn list_folding() { - let generated_air = Test::new("tests/list_folding/list_folding.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../list_folding/list_folding_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn selectors() { - let generated_air = Test::new("tests/selectors/selectors.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../selectors/selectors_plonky3.rs"]; - expected.assert_eq(&generated_air); - - let generated_air = Test::new("tests/selectors/selectors_with_evaluators.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../selectors/selectors_with_evaluators_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn selectors_combine_simple() { - let generated_air = Test::new("tests/selectors/selectors_combine_simple.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../selectors/selectors_combine_simple_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn selectors_combine_complex() { - let generated_air = Test::new("tests/selectors/selectors_combine_complex.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../selectors/selectors_combine_complex_plonky3.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn constraint_comprehension() { - let generated_air = - Test::new("tests/constraint_comprehension/constraint_comprehension.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../constraint_comprehension/constraint_comprehension_plonky3.rs"]; - expected.assert_eq(&generated_air); - - let generated_air = - Test::new("tests/constraint_comprehension/cc_with_evaluators.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); - - let expected = expect_file!["../constraint_comprehension/constraint_comprehension_plonky3.rs"]; - expected.assert_eq(&generated_air); -} diff --git a/air-script/tests/codegen/winterfell.rs b/air-script/tests/codegen/winterfell.rs deleted file mode 100644 index 28a993cd6..000000000 --- a/air-script/tests/codegen/winterfell.rs +++ /dev/null @@ -1,335 +0,0 @@ -use expect_test::expect_file; - -use super::helpers::{Target, Test}; - -#[test] -fn binary() { - let generated_air = Test::new("tests/binary/binary.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../binary/binary.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn bitwise() { - let generated_air = Test::new("tests/bitwise/bitwise.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../bitwise/bitwise.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_complex() { - let generated_air = Test::new("tests/buses/buses_complex.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../buses/buses_complex.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_simple() { - let generated_air = Test::new("tests/buses/buses_simple.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../buses/buses_simple.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_simple_with_evaluators() { - let generated_air = Test::new("tests/buses/buses_simple_with_evaluators.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../buses/buses_simple.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_varlen_boundary_both() { - let generated_air = Test::new("tests/buses/buses_varlen_boundary_both.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../buses/buses_varlen_boundary_both.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_varlen_boundary_first() { - let generated_air = Test::new("tests/buses/buses_varlen_boundary_first.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../buses/buses_varlen_boundary_first.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn buses_varlen_boundary_last() { - let generated_air = Test::new("tests/buses/buses_varlen_boundary_last.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../buses/buses_varlen_boundary_last.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn computed_indices_complex() { - let generated_air = - Test::new("tests/computed_indices/computed_indices_complex.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../computed_indices/computed_indices_complex.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn computed_indices_simple() { - let generated_air = Test::new("tests/computed_indices/computed_indices_simple.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../computed_indices/computed_indices_simple.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn constant_in_range() { - let generated_air = Test::new("tests/constant_in_range/constant_in_range.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../constant_in_range/constant_in_range.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn constants() { - let generated_air = Test::new("tests/constants/constants.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../constants/constants.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn constraint_comprehension() { - let generated_air = - Test::new("tests/constraint_comprehension/constraint_comprehension.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../constraint_comprehension/constraint_comprehension.rs"]; - expected.assert_eq(&generated_air); - - let generated_air = - Test::new("tests/constraint_comprehension/cc_with_evaluators.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../constraint_comprehension/constraint_comprehension.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn evaluators() { - let generated_air = Test::new("tests/evaluators/evaluators.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../evaluators/evaluators.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn fibonacci() { - let generated_air = Test::new("tests/fibonacci/fibonacci.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../fibonacci/fibonacci.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn functions_complex() { - let generated_air = Test::new("tests/functions/functions_complex.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../functions/functions_complex.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn functions_simple() { - let generated_air = Test::new("tests/functions/functions_simple.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../functions/functions_simple.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn functions_simple_inlined() { - // make sure that the constraints generated using inlined functions are the same as the ones - // generated using regular functions - let generated_air = Test::new("tests/functions/inlined_functions_simple.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../functions/functions_simple.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn indexed_trace_access() { - let generated_air = - Test::new("tests/indexed_trace_access/indexed_trace_access.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../indexed_trace_access/indexed_trace_access.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn list_comprehension() { - let generated_air = Test::new("tests/list_comprehension/list_comprehension.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../list_comprehension/list_comprehension.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn list_comprehension_nested() { - let generated_air = - Test::new("tests/list_comprehension/list_comprehension_nested.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../list_comprehension/list_comprehension_nested.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn list_folding() { - let generated_air = Test::new("tests/list_folding/list_folding.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../list_folding/list_folding.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn periodic_columns() { - let generated_air = Test::new("tests/periodic_columns/periodic_columns.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../periodic_columns/periodic_columns.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn pub_inputs() { - let generated_air = Test::new("tests/pub_inputs/pub_inputs.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../pub_inputs/pub_inputs.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn selectors() { - let generated_air = Test::new("tests/selectors/selectors.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../selectors/selectors.rs"]; - expected.assert_eq(&generated_air); - - let generated_air = Test::new("tests/selectors/selectors_with_evaluators.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../selectors/selectors_with_evaluators.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn selectors_combine_simple() { - let generated_air = Test::new("tests/selectors/selectors_combine_simple.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../selectors/selectors_combine_simple.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn selectors_combine_complex() { - let generated_air = Test::new("tests/selectors/selectors_combine_complex.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../selectors/selectors_combine_complex.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn selectors_combine_with_list_comprehensions() { - let generated_air = - Test::new("tests/selectors/selectors_combine_with_list_comprehensions.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../selectors/selectors_combine_with_list_comprehensions.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn system() { - let generated_air = Test::new("tests/system/system.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../system/system.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn trace_col_groups() { - let generated_air = Test::new("tests/trace_col_groups/trace_col_groups.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../trace_col_groups/trace_col_groups.rs"]; - expected.assert_eq(&generated_air); -} - -#[test] -fn variables() { - let generated_air = Test::new("tests/variables/variables.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); - - let expected = expect_file!["../variables/variables.rs"]; - expected.assert_eq(&generated_air); -} diff --git a/air-script/tests/computed_indices/mod.rs b/air-script/tests/computed_indices/mod.rs deleted file mode 100644 index 5f582b136..000000000 --- a/air-script/tests/computed_indices/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[rustfmt::skip] -#[allow(clippy::all)] -mod computed_indices_complex; -#[rustfmt::skip] -#[allow(clippy::all)] -mod computed_indices_simple; -mod test_air; diff --git a/air-script/tests/helpers/mod.rs b/air-script/tests/helpers/mod.rs deleted file mode 100644 index 077bab5f1..000000000 --- a/air-script/tests/helpers/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Deprectated: use updated AirScriptAir and AirScriptBuilder traits instead -//mod plonky3_periodic_columns; -//pub use plonky3_periodic_columns::*; - -mod plonky3_traits; -mod winterfell_test_helpers; - -pub use winterfell_test_helpers::*; -pub mod macros; - -pub use plonky3_traits::*; diff --git a/air-script/tests/helpers/plonky3_periodic_columns.rs b/air-script/tests/helpers/plonky3_periodic_columns.rs deleted file mode 100644 index 245a8d037..000000000 --- a/air-script/tests/helpers/plonky3_periodic_columns.rs +++ /dev/null @@ -1,146 +0,0 @@ -use p3_air::{Air, AirBuilder, AirBuilderWithPublicValues, BaseAir}; -use p3_field::Field; -use p3_matrix::{ - Matrix, - dense::{RowMajorMatrix, RowMajorMatrixView}, - stack::VerticalPair, -}; - -pub trait BaseAirWithPeriodicColumns: BaseAir { - fn get_periodic_columns(&self) -> Vec> { - vec![] - } -} - -pub trait AirBuilderWithPeriodicColumns: AirBuilder { - type PeriodicColumnsVar: Field + Into; - - fn periodic_columns(&self) -> Vec { - vec![] - } -} - -pub(crate) fn check_constraints_with_periodic_columns( - air: &A, - main: &RowMajorMatrix, - public_values: &Vec, -) where - F: Field, - A: for<'a> Air> - + BaseAirWithPeriodicColumns, -{ - let height = main.height(); - - (0..height).for_each(|i| { - let i_next = (i + 1) % height; - - let local = main.row_slice(i).unwrap(); // i < height so unwrap should never fail. - let next = main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail. - let main = VerticalPair::new( - RowMajorMatrixView::new_row(&*local), - RowMajorMatrixView::new_row(&*next), - ); - let periodic_columns = air.get_periodic_columns(); - - let mut builder = DebugConstraintBuilderWithPeriodicColumns { - row_index: i, - main, - public_values, - is_first_row: F::from_bool(i == 0), - is_last_row: F::from_bool(i == height - 1), - is_transition: F::from_bool(i != height - 1), - periodic_columns, - }; - - air.eval(&mut builder); - }); -} - -/// A builder that runs constraint assertions during testing. -/// -/// Used in conjunction with [`check_constraints`] to simulate -/// an execution trace and verify that the AIR logic enforces all constraints. -#[derive(Debug)] -pub struct DebugConstraintBuilderWithPeriodicColumns<'a, F: Field> { - /// The index of the row currently being evaluated. - row_index: usize, - /// A view of the current and next row as a vertical pair. - main: VerticalPair, RowMajorMatrixView<'a, F>>, - /// The public values provided for constraint validation (e.g. inputs or outputs). - public_values: &'a [F], - /// A flag indicating whether this is the first row. - is_first_row: F, - /// A flag indicating whether this is the last row. - is_last_row: F, - /// A flag indicating whether this is a transition row (not the last row). - is_transition: F, - /// The periodic columns provided for constraint validation. - periodic_columns: Vec>, -} - -impl<'a, F> AirBuilderWithPeriodicColumns for DebugConstraintBuilderWithPeriodicColumns<'a, F> -where - F: Field + Into, -{ - type PeriodicColumnsVar = F; - - fn periodic_columns(&self) -> Vec { - self.periodic_columns - .iter() - .map(|col| col[self.row_index % col.len()]) - .collect::>() - } -} - -impl<'a, F> AirBuilder for DebugConstraintBuilderWithPeriodicColumns<'a, F> -where - F: Field, -{ - type F = F; - type Expr = F; - type Var = F; - type M = VerticalPair, RowMajorMatrixView<'a, F>>; - - fn main(&self) -> Self::M { - self.main - } - - fn is_first_row(&self) -> Self::Expr { - self.is_first_row - } - - fn is_last_row(&self) -> Self::Expr { - self.is_last_row - } - - /// # Panics - /// This function panics if `size` is not `2`. - fn is_transition_window(&self, size: usize) -> Self::Expr { - if size == 2 { - self.is_transition - } else { - panic!("only supports a window size of 2") - } - } - - fn assert_zero>(&mut self, x: I) { - assert_eq!(x.into(), F::ZERO, "constraints had nonzero value on row {}", self.row_index); - } - - fn assert_eq, I2: Into>(&mut self, x: I1, y: I2) { - let x = x.into(); - let y = y.into(); - assert_eq!(x, y, "values didn't match on row {}: {} != {}", self.row_index, x, y); - } -} - -impl<'a, F> AirBuilderWithPublicValues for DebugConstraintBuilderWithPeriodicColumns<'a, F> -where - F: Field, -{ - type PublicVar = Self::F; - - fn public_values(&self) -> &[Self::F] { - self.public_values - } -} diff --git a/codegen/plonky3/src/imports.rs b/codegen/plonky3/src/imports.rs index b7e6e81ec..f26389b44 100644 --- a/codegen/plonky3/src/imports.rs +++ b/codegen/plonky3/src/imports.rs @@ -11,6 +11,6 @@ pub(super) fn add_imports(scope: &mut Scope) { scope.import("p3_matrix", "Matrix"); scope.import("p3_field", "Field"); scope.import("p3_field", "PrimeCharacteristicRing"); - scope.import("crate::helpers", "AirScriptAir"); - scope.import("crate::helpers", "AirScriptBuilder"); + scope.import("crate::test_utils::plonky3_traits", "AirScriptAir"); + scope.import("crate::test_utils::plonky3_traits", "AirScriptBuilder"); } From de9088a4cdf11ab9b31dfbf6ba15fd956d1778be Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Wed, 12 Nov 2025 08:33:05 +0100 Subject: [PATCH 09/22] tests: add codegen script to help update all e2e tests --- scripts/generate_all_e2e_tests.sh | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 scripts/generate_all_e2e_tests.sh diff --git a/scripts/generate_all_e2e_tests.sh b/scripts/generate_all_e2e_tests.sh new file mode 100644 index 000000000..b27c6fe0c --- /dev/null +++ b/scripts/generate_all_e2e_tests.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# Notes: +# - Run from root of repository +# - We avoid looping on all found air-script/src/tests/**/*.air files to make it easier to notice changes + +cargo build --release + +# Winterfell Backend + +./target/release/airc transpile --target winterfell .\air-script\src\tests\binary\binary.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\bitwise\bitwise.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_complex.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_simple.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_simple_with_evaluators.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_varlen_boundary_both.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_varlen_boundary_last.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_varlen_boundary_first.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\constant_in_range\constant_in_range.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\constants\constants.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\constraint_comprehension\constraint_comprehension.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\evaluators\evaluators.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\fibonacci\fibonacci.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\functions\functions_simple.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\functions\functions_complex.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\indexed_trace_access\indexed_trace_access.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\list_comprehension\list_comprehension_nested.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\list_comprehension\list_comprehension.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\list_folding\list_folding.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\periodic_columns\periodic_columns.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\pub_inputs\pub_inputs.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors_combine_complex.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors_combine_simple.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors_combine_with_list_comprehensions.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors_with_evaluators.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\system\system.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\trace_col_groups\trace_col_groups.air +./target/release/airc transpile --target winterfell .\air-script\src\tests\variables\variables.air + +# Plonky3 Backend +./target/release/airc transpile --target plonky3 .\air-script\src\tests\binary\binary.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\bitwise\bitwise.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_complex.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_simple.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_simple_with_evaluators.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_varlen_boundary_both.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_varlen_boundary_last.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_varlen_boundary_first.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\computed_indices\computed_indices_complex.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\computed_indices\computed_indices_simple.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\constant_in_range\constant_in_range.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\constants\constants.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\constraint_comprehension\constraint_comprehension.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\evaluators\evaluators.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\fibonacci\fibonacci.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\functions\functions_simple.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\functions\functions_complex.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\indexed_trace_access\indexed_trace_access.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\list_comprehension\list_comprehension_nested.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\list_comprehension\list_comprehension.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\list_folding\list_folding.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\periodic_columns\periodic_columns.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\pub_inputs\pub_inputs.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\selectors\selectors_combine_complex.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\selectors\selectors_combine_simple.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\selectors\selectors_combine_with_list_comprehensions.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\selectors\selectors_with_evaluators.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\selectors\selectors.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\system\system.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\trace_col_groups\trace_col_groups.air +./target/release/airc transpile --target plonky3 .\air-script\src\tests\variables\variables.air From d81248b82d87019657fd83a4b95ec4a1e203d446 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Wed, 12 Nov 2025 08:33:44 +0100 Subject: [PATCH 10/22] refactor: review comments --- .../plonky3/src/air/boundary_constraints.rs | 39 +++++-------------- .../plonky3/src/air/integrity_constraints.rs | 18 +++------ codegen/plonky3/src/air/mod.rs | 1 - 3 files changed, 15 insertions(+), 43 deletions(-) diff --git a/codegen/plonky3/src/air/boundary_constraints.rs b/codegen/plonky3/src/air/boundary_constraints.rs index 89da2bf5b..aba2206b0 100644 --- a/codegen/plonky3/src/air/boundary_constraints.rs +++ b/codegen/plonky3/src/air/boundary_constraints.rs @@ -5,12 +5,9 @@ use crate::air::graph::constraint_to_string; /// Adds the main boundary constraints to the generated code. pub(super) fn add_main_boundary_constraints(eval_func: &mut Function, ir: &Air) { - let constraints = ir.boundary_constraints(TraceSegmentId::Main); - if !constraints.is_empty() { - eval_func.line(""); - eval_func.line("// Main boundary constraints"); - } - for constraint in constraints { + eval_func.line(""); + eval_func.line("// Main boundary constraints"); + for constraint in ir.boundary_constraints(TraceSegmentId::Main) { let assertion = constraint_to_string(ir, constraint, true); eval_func.line(assertion); } @@ -18,32 +15,14 @@ pub(super) fn add_main_boundary_constraints(eval_func: &mut Function, ir: &Air) /// Adds the aux boundary constraints to the generated code. pub(super) fn add_aux_boundary_constraints(eval_func: &mut Function, ir: &Air) { - let constraints = ir.boundary_constraints(TraceSegmentId::Aux); - if !constraints.is_empty() { - eval_func.line(""); - eval_func.line("// Aux boundary constraints"); - } - for constraint in constraints { + eval_func.line(""); + eval_func.line("// Aux boundary constraints"); + for constraint in ir.boundary_constraints(TraceSegmentId::Aux) { let assertion = constraint_to_string(ir, constraint, true); eval_func.line(assertion); - // TODO: add code to handle aux boundary constraints - - /*// For first row constraints, we can use `when_first_row` to conditionally apply the assertion - if constraint.domain() == ConstraintDomain::FirstRow { - let expr_root = constraint.node_index(); - let expr_root_string = expr_root.to_string(ir, ElemType::Ext); - - let assertion = format!("builder.when_first_row().assert_zero_ext({expr_root_string});"); - eval_func.line(assertion); - } else { - let assertion = constraint_to_string(ir, constraint, false); - - let domain_flag = get_domain_flag_str(&constraint.domain()); - let extension_field_flag = get_extension_field_flag_str(ir, *expr_root); - let assertion = format!("builder{domain_flag}.assert_zero{extension_field_flag}({expr_root_string});"); - - eval_func.line(assertion); - }*/ + // TODO: better check assumptions on aux boundary constraints: + // - start only with empty buses, + // - end with values derived from builder.aux_bus_boundary_value() } } diff --git a/codegen/plonky3/src/air/integrity_constraints.rs b/codegen/plonky3/src/air/integrity_constraints.rs index 074a7ee3c..bdcce45e1 100644 --- a/codegen/plonky3/src/air/integrity_constraints.rs +++ b/codegen/plonky3/src/air/integrity_constraints.rs @@ -5,12 +5,9 @@ use crate::air::graph::constraint_to_string; /// Adds the main integrity constraints to the generated code. pub(super) fn add_main_integrity_constraints(eval_func: &mut Function, ir: &Air) { - let constraints = ir.integrity_constraints(TraceSegmentId::Main); - if !constraints.is_empty() { - eval_func.line(""); - eval_func.line("// Main integrity/transition constraints"); - } - for constraint in constraints { + eval_func.line(""); + eval_func.line("// Main integrity/transition constraints"); + for constraint in ir.integrity_constraints(TraceSegmentId::Main) { let assertion = constraint_to_string(ir, constraint, false); eval_func.line(assertion); } @@ -18,12 +15,9 @@ pub(super) fn add_main_integrity_constraints(eval_func: &mut Function, ir: &Air) /// Adds the aux integrity constraints to the generated code. pub(super) fn add_aux_integrity_constraints(eval_func: &mut Function, ir: &Air) { - let constraints = ir.integrity_constraints(TraceSegmentId::Aux); - if !constraints.is_empty() { - eval_func.line(""); - eval_func.line("// Aux integrity/transition constraints"); - } - for constraint in constraints { + eval_func.line(""); + eval_func.line("// Aux integrity/transition constraints"); + for constraint in ir.integrity_constraints(TraceSegmentId::Aux) { let assertion = constraint_to_string(ir, constraint, false); eval_func.line(assertion); } diff --git a/codegen/plonky3/src/air/mod.rs b/codegen/plonky3/src/air/mod.rs index 21a1239a6..70c68a02d 100644 --- a/codegen/plonky3/src/air/mod.rs +++ b/codegen/plonky3/src/air/mod.rs @@ -105,7 +105,6 @@ fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { let periodic_table_func = air_script_impl .new_fn("periodic_table") .arg_ref_self() - //.ret("&'static [&'static [F]]"); .ret("Vec>"); if ir.periodic_columns().count() == 0 { periodic_table_func.line("vec![]"); From 1e71f68131c675c4852dbade02fcfdd90b8f28a3 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Wed, 12 Nov 2025 08:39:37 +0100 Subject: [PATCH 11/22] chore: fmt + test fixes --- air-script/src/test_utils/codegen.rs | 3 ++- air-script/src/test_utils/mod.rs | 1 - .../src/tests/list_comprehension/mod.rs | 7 +++++++ air-script/src/tests/plonky3.rs | 21 +++++++++++-------- air-script/src/tests/selectors/mod.rs | 4 ++++ air-script/src/tests/winterfell.rs | 14 +++++++------ codegen/plonky3/src/air/mod.rs | 6 ++---- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/air-script/src/test_utils/codegen.rs b/air-script/src/test_utils/codegen.rs index 5dbcbba8d..9e68ca753 100644 --- a/air-script/src/test_utils/codegen.rs +++ b/air-script/src/test_utils/codegen.rs @@ -1,11 +1,12 @@ use std::sync::Arc; -use crate::compile; use air_ir::{CodeGenerator, CompileError}; use miden_diagnostics::{ CodeMap, DefaultEmitter, DiagnosticsHandler, term::termcolor::ColorChoice, }; +use crate::compile; + pub enum Target { Winterfell, Plonky3, diff --git a/air-script/src/test_utils/mod.rs b/air-script/src/test_utils/mod.rs index 91742998c..1fe4b9486 100644 --- a/air-script/src/test_utils/mod.rs +++ b/air-script/src/test_utils/mod.rs @@ -1,4 +1,3 @@ - /// Macros to generate Air tester structs and tests for both Plonky3 and Winterfell backends. pub mod air_tester_macros; /// Code generation for tests/**/*.air files. diff --git a/air-script/src/tests/list_comprehension/mod.rs b/air-script/src/tests/list_comprehension/mod.rs index eb8e94340..e33f216df 100644 --- a/air-script/src/tests/list_comprehension/mod.rs +++ b/air-script/src/tests/list_comprehension/mod.rs @@ -1,5 +1,12 @@ #[rustfmt::skip] #[allow(clippy::all)] +mod list_comprehension_nested; +#[rustfmt::skip] +#[allow(clippy::all)] +#[allow(unused_imports)] +mod list_comprehension_nested_plonky3; +#[rustfmt::skip] +#[allow(clippy::all)] mod list_comprehension; #[rustfmt::skip] #[allow(clippy::all)] diff --git a/air-script/src/tests/plonky3.rs b/air-script/src/tests/plonky3.rs index 71c5c2c87..e599d2189 100644 --- a/air-script/src/tests/plonky3.rs +++ b/air-script/src/tests/plonky3.rs @@ -94,9 +94,10 @@ fn computed_indices_complex() { #[test] fn computed_indices_simple() { - let generated_air = Test::new("src/tests/computed_indices/computed_indices_simple.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); + let generated_air = + Test::new("src/tests/computed_indices/computed_indices_simple.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); let expected = expect_file!["computed_indices/computed_indices_simple_plonky3.rs"]; expected.assert_eq(&generated_air); @@ -198,9 +199,10 @@ fn list_comprehension_nested() { #[test] fn list_comprehension() { - let generated_air = Test::new("src/tests/list_comprehension/list_comprehension.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); + let generated_air = + Test::new("src/tests/list_comprehension/list_comprehension.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); let expected = expect_file!["list_comprehension/list_comprehension_plonky3.rs"]; expected.assert_eq(&generated_air); @@ -258,9 +260,10 @@ fn selectors_combine_simple() { #[test] fn selectors_combine_with_list_comprehensions() { - let generated_air = Test::new("src/tests/selectors/selectors_combine_with_list_comprehensions.air".to_string()) - .transpile(Target::Plonky3) - .unwrap(); + let generated_air = + Test::new("src/tests/selectors/selectors_combine_with_list_comprehensions.air".to_string()) + .transpile(Target::Plonky3) + .unwrap(); let expected = expect_file!["selectors/selectors_combine_with_list_comprehensions_plonky3.rs"]; expected.assert_eq(&generated_air); diff --git a/air-script/src/tests/selectors/mod.rs b/air-script/src/tests/selectors/mod.rs index 39924b2bc..a8007ac23 100644 --- a/air-script/src/tests/selectors/mod.rs +++ b/air-script/src/tests/selectors/mod.rs @@ -16,6 +16,10 @@ mod selectors_with_evaluators; #[rustfmt::skip] #[allow(clippy::all)] #[allow(unused_imports)] +mod selectors_plonky3; +#[rustfmt::skip] +#[allow(clippy::all)] +#[allow(unused_imports)] mod selectors_combine_simple_plonky3; #[rustfmt::skip] #[allow(clippy::all)] diff --git a/air-script/src/tests/winterfell.rs b/air-script/src/tests/winterfell.rs index a63eff87d..2b2683cb6 100644 --- a/air-script/src/tests/winterfell.rs +++ b/air-script/src/tests/winterfell.rs @@ -95,9 +95,10 @@ fn computed_indices_complex() { #[test] fn computed_indices_simple() { - let generated_air = Test::new("src/tests/computed_indices/computed_indices_simple.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); + let generated_air = + Test::new("src/tests/computed_indices/computed_indices_simple.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); let expected = expect_file!["computed_indices/computed_indices_simple.rs"]; expected.assert_eq(&generated_air); @@ -207,9 +208,10 @@ fn indexed_trace_access() { #[test] fn list_comprehension() { - let generated_air = Test::new("src/tests/list_comprehension/list_comprehension.air".to_string()) - .transpile(Target::Winterfell) - .unwrap(); + let generated_air = + Test::new("src/tests/list_comprehension/list_comprehension.air".to_string()) + .transpile(Target::Winterfell) + .unwrap(); let expected = expect_file!["list_comprehension/list_comprehension.rs"]; expected.assert_eq(&generated_air); diff --git a/codegen/plonky3/src/air/mod.rs b/codegen/plonky3/src/air/mod.rs index 70c68a02d..7f4bc3270 100644 --- a/codegen/plonky3/src/air/mod.rs +++ b/codegen/plonky3/src/air/mod.rs @@ -102,10 +102,8 @@ fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { .line("NUM_ALPHA_CHALLENGES"); // add the periodic_table function - let periodic_table_func = air_script_impl - .new_fn("periodic_table") - .arg_ref_self() - .ret("Vec>"); + let periodic_table_func = + air_script_impl.new_fn("periodic_table").arg_ref_self().ret("Vec>"); if ir.periodic_columns().count() == 0 { periodic_table_func.line("vec![]"); } else { From e2f86e92cf2943d007c0aac5435de41cf4c8bc8e Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Wed, 12 Nov 2025 10:11:22 +0100 Subject: [PATCH 12/22] refactor: reverse the roles of alpha and beta, fix permutation_randomness --- air-script/src/test_utils/plonky3_traits.rs | 132 +++++++++--------- air-script/src/tests/binary/binary_plonky3.rs | 6 +- .../src/tests/bitwise/bitwise_plonky3.rs | 6 +- .../src/tests/buses/buses_complex_plonky3.rs | 14 +- .../src/tests/buses/buses_simple_plonky3.rs | 14 +- .../buses_simple_with_evaluators_plonky3.rs | 14 +- .../buses_varlen_boundary_both_plonky3.rs | 14 +- .../buses_varlen_boundary_first_plonky3.rs | 14 +- .../buses_varlen_boundary_last_plonky3.rs | 14 +- .../computed_indices_complex_plonky3.rs | 6 +- .../computed_indices_simple_plonky3.rs | 6 +- .../constant_in_range_plonky3.rs | 6 +- .../src/tests/constants/constants_plonky3.rs | 6 +- .../constraint_comprehension_plonky3.rs | 6 +- .../tests/evaluators/evaluators_plonky3.rs | 6 +- .../src/tests/fibonacci/fibonacci_plonky3.rs | 6 +- .../functions/functions_complex_plonky3.rs | 6 +- .../functions/functions_simple_plonky3.rs | 6 +- .../indexed_trace_access_plonky3.rs | 6 +- .../list_comprehension_nested_plonky3.rs | 6 +- .../list_comprehension_plonky3.rs | 6 +- .../list_folding/list_folding_plonky3.rs | 6 +- .../periodic_columns_plonky3.rs | 6 +- .../tests/pub_inputs/pub_inputs_plonky3.rs | 6 +- .../selectors_combine_complex_plonky3.rs | 12 +- .../selectors_combine_simple_plonky3.rs | 6 +- ...ombine_with_list_comprehensions_plonky3.rs | 6 +- .../src/tests/selectors/selectors_plonky3.rs | 6 +- .../selectors_with_evaluators_plonky3.rs | 6 +- air-script/src/tests/system/system_plonky3.rs | 6 +- .../trace_col_groups_plonky3.rs | 6 +- .../src/tests/variables/variables_plonky3.rs | 6 +- codegen/plonky3/src/air/graph.rs | 4 +- codegen/plonky3/src/air/mod.rs | 14 +- 34 files changed, 198 insertions(+), 192 deletions(-) diff --git a/air-script/src/test_utils/plonky3_traits.rs b/air-script/src/test_utils/plonky3_traits.rs index 644685224..b5ee08c0d 100644 --- a/air-script/src/test_utils/plonky3_traits.rs +++ b/air-script/src/test_utils/plonky3_traits.rs @@ -15,8 +15,8 @@ pub trait AirScriptAir> { 0 } - /// Number of alpha challenges used in the AIR. - fn num_alpha_challenges(&self) -> usize { + /// Number of beta challenges used in the AIR. + fn num_beta_challenges(&self) -> usize { 0 } @@ -39,8 +39,8 @@ where /// Global challenges in EF. (We can provide defaults; details not important here.) fn alpha(&self) -> ::VarEF; - fn alpha_powers(&self) -> &[::VarEF]; fn beta(&self) -> ::VarEF; + fn beta_powers(&self) -> &[::VarEF]; /// Aux bus boundary values: EF finals, one per aux/bus column, carried in the proof. fn aux_bus_boundary_values(&self) -> &[::VarEF]; @@ -70,10 +70,12 @@ pub struct DebugConstraintBuilderWithAirScriptTraits<'a, F: Field, EF: Extension periodic_columns: Vec, /// The alpha challenge in the extension field. alpha: EF, - /// The alpha powers in the extension field. - alpha_powers: Vec, /// The beta challenge in the extension field. beta: EF, + /// The beta powers in the extension field. + beta_powers: Vec, + /// The permutation randomness in the extension field. + permutation_randomness: Vec, /// The aux bus boundary values in the extension field. aux_bus_boundary_values: Vec, } @@ -171,7 +173,7 @@ where } fn permutation_randomness(&self) -> &[Self::RandomVar] { - self.alpha_powers.as_slice() + self.permutation_randomness.as_slice() } } @@ -188,8 +190,8 @@ where self.alpha } - fn alpha_powers(&self) -> &[::VarEF] { - self.alpha_powers.as_slice() + fn beta_powers(&self) -> &[::VarEF] { + self.beta_powers.as_slice() } fn beta(&self) -> ::VarEF { @@ -203,8 +205,8 @@ where fn compute_aux_transition( main: VerticalPair, RowMajorMatrixView>, - alpha_challenges: Vec, - beta: EF, + alpha: EF, + beta_challenges: Vec, aux_current: [EF; 2], ) -> [EF; 2] where @@ -216,28 +218,28 @@ where // First bus: multiset // p' * multiset_removals = p * multiset_inserts - let multiset_inserts: EF = ((beta - + alpha_challenges[0] - + (EF::from_u64(3) + EF::from(main_current[1].clone())) * alpha_challenges[1] - + EF::from(main_current[0].clone()) * alpha_challenges[2]) + let multiset_inserts: EF = ((alpha + + beta_challenges[0] + + (EF::from_u64(3) + EF::from(main_current[1].clone())) * beta_challenges[1] + + EF::from(main_current[0].clone()) * beta_challenges[2]) * EF::from(main_current[2].clone()) + EF::ONE - EF::from(main_current[2].clone())) - * ((beta - + alpha_challenges[0].double() - + EF::from(main_current[1].clone()) * alpha_challenges[1]) + * ((alpha + + beta_challenges[0].double() + + EF::from(main_current[1].clone()) * beta_challenges[1]) * (EF::ONE - EF::from(main_current[2].clone())) + EF::from(main_current[2].clone())); - let multiset_removals: EF = ((beta - + alpha_challenges[0] - + (EF::from_u64(3) + EF::from(main_current[1].clone())) * alpha_challenges[1] - + EF::from(main_current[1].clone()) * alpha_challenges[2]) + let multiset_removals: EF = ((alpha + + beta_challenges[0] + + (EF::from_u64(3) + EF::from(main_current[1].clone())) * beta_challenges[1] + + EF::from(main_current[1].clone()) * beta_challenges[2]) * EF::from(main_current[3].clone()) + EF::ONE - EF::from(main_current[3].clone())) - * ((beta - + alpha_challenges[0].double() - + EF::from(main_current[0].clone()) * alpha_challenges[1]) + * ((alpha + + beta_challenges[0].double() + + EF::from(main_current[0].clone()) * beta_challenges[1]) * (EF::ONE - EF::from(main_current[3].clone())) + EF::from(main_current[3].clone())); let multiset_current = EF::from(aux_current[0].clone()); @@ -245,44 +247,44 @@ where // Second bus: logup // 0 = A * q + B + C - D * q' - E; - let a: EF = (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[0].clone()) * alpha_challenges[1]) - * (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[0].clone()) * alpha_challenges[1]) - * (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[1].clone()) * alpha_challenges[1]); - let b: EF = (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[0].clone()) * alpha_challenges[1]) - * (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[1].clone()) * alpha_challenges[1]) + let a: EF = (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[0].clone()) * beta_challenges[1]) + * (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[0].clone()) * beta_challenges[1]) + * (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[1].clone()) * beta_challenges[1]); + let b: EF = (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[0].clone()) * beta_challenges[1]) + * (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[1].clone()) * beta_challenges[1]) * EF::from(main_current[4].clone()); - let c: EF = (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[0].clone()) * alpha_challenges[1]) - * (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[1].clone()) * alpha_challenges[1]) + let c: EF = (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[0].clone()) * beta_challenges[1]) + * (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[1].clone()) * beta_challenges[1]) * EF::from(main_current[5].clone()); - let d: EF = (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[0].clone()) * alpha_challenges[1]) - * (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[0].clone()) * alpha_challenges[1]) - * (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[1].clone()) * alpha_challenges[1]); - let e: EF = (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[0].clone()) * alpha_challenges[1]) - * (beta - + EF::from_u64(3) * alpha_challenges[0] - + EF::from(main_current[0].clone()) * alpha_challenges[1]) + let d: EF = (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[0].clone()) * beta_challenges[1]) + * (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[0].clone()) * beta_challenges[1]) + * (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[1].clone()) * beta_challenges[1]); + let e: EF = (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[0].clone()) * beta_challenges[1]) + * (alpha + + EF::from_u64(3) * beta_challenges[0] + + EF::from(main_current[0].clone()) * beta_challenges[1]) * EF::from(main_current[6].clone()); let logup_current = EF::from(aux_current[1].clone()); let logup_next = (a * logup_current + b + c - e) * d.inverse(); @@ -307,9 +309,12 @@ pub(crate) fn check_constraints_with_airscript_traits( let alpha_f: Vec = (0..5).map(|i| F::from_u64(123456789 * i)).collect(); // Dummy alpha in F let alpha = EF::from_basis_coefficients_iter(alpha_f.iter().cloned()).unwrap(); let beta = EF::from_u64(987654321); - let alpha_powers: Vec = (0..air.num_alpha_challenges()) + let beta_powers: Vec = (0..air.num_beta_challenges()) .map(|power| alpha.exp_u64(power as u64)) .collect(); + let mut permutation_randomness = Vec::with_capacity(1 + beta_powers.len()); + permutation_randomness.push(alpha); + permutation_randomness.extend_from_slice(beta_powers.as_slice()); let initial_aux = [EF::ONE, EF::ZERO]; @@ -333,7 +338,7 @@ pub(crate) fn check_constraints_with_airscript_traits( let aux_local = current_aux_values; if air.aux_width() > 0 && i != height - 1 { current_aux_values = - compute_aux_transition::(main, alpha_powers.clone(), beta, aux_local); + compute_aux_transition::(main, alpha, beta_powers.clone(), aux_local); } let aux_next = current_aux_values; let aux = VerticalPair::new( @@ -354,7 +359,8 @@ pub(crate) fn check_constraints_with_airscript_traits( periodic_columns, alpha, beta, - alpha_powers: alpha_powers.clone(), + beta_powers: beta_powers.clone(), + permutation_randomness: permutation_randomness.clone(), aux_bus_boundary_values: aux_bus_boundary_values.clone(), }; diff --git a/air-script/src/tests/binary/binary_plonky3.rs b/air-script/src/tests/binary/binary_plonky3.rs index d9f4dc26d..29dde9c4b 100644 --- a/air-script/src/tests/binary/binary_plonky3.rs +++ b/air-script/src/tests/binary/binary_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct BinaryAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BinaryAir { AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/bitwise/bitwise_plonky3.rs b/air-script/src/tests/bitwise/bitwise_plonky3.rs index be2ed40ae..cf07625ab 100644 --- a/air-script/src/tests/bitwise/bitwise_plonky3.rs +++ b/air-script/src/tests/bitwise/bitwise_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 2; pub const PERIOD: usize = 8; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct BitwiseAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BitwiseAir { AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/buses/buses_complex_plonky3.rs b/air-script/src/tests/buses/buses_complex_plonky3.rs index 4c591450b..1e2a83fe7 100644 --- a/air-script/src/tests/buses/buses_complex_plonky3.rs +++ b/air-script/src/tests/buses/buses_complex_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_ALPHA_CHALLENGES: usize = 3; +pub const NUM_BETA_CHALLENGES: usize = 3; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { @@ -45,8 +45,8 @@ impl> AirScriptAir for BusesAir { main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); - let beta = builder.beta(); + let alpha = builder.alpha(); + let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -68,8 +68,8 @@ impl> AirScriptAir for BusesAir { builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); // Aux integrity/transition constraints - builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into() + (AB::ExprEF::from_u64(3) + AB::ExprEF::from(main_current[1].clone().into())) * alpha_challenges[1].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[2].into()) * AB::ExprEF::from(main_current[2].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[2].clone().into())) * ((beta.into() + alpha_challenges[0].into().double() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[1].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[2].clone().into())) + AB::ExprEF::from(main_current[2].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + (AB::ExprEF::from_u64(3) + AB::ExprEF::from(main_current[1].clone().into())) * alpha_challenges[1].into() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[2].into()) * AB::ExprEF::from(main_current[3].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[3].clone().into())) * ((beta.into() + alpha_challenges[0].into().double() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[3].clone().into())) + AB::ExprEF::from(main_current[3].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); - builder.when_transition().assert_zero_ext((beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[1].into()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[1].into()) * AB::ExprEF::from(main_current[4].clone().into()) + (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[1].into()) * AB::ExprEF::from(main_current[5].clone().into()) - ((beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * alpha_challenges[1].into()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * (beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * alpha_challenges[1].into()) * AB::ExprEF::from(main_current[6].clone().into()))); + builder.when_transition().assert_zero_ext(((alpha.into() + beta_challenges[0].into() + (AB::ExprEF::from_u64(3) + AB::ExprEF::from(main_current[1].clone().into())) * beta_challenges[1].into() + AB::ExprEF::from(main_current[0].clone().into()) * beta_challenges[2].into()) * AB::ExprEF::from(main_current[2].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[2].clone().into())) * ((alpha.into() + beta_challenges[0].into().double() + AB::ExprEF::from(main_current[1].clone().into()) * beta_challenges[1].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[2].clone().into())) + AB::ExprEF::from(main_current[2].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into() + (AB::ExprEF::from_u64(3) + AB::ExprEF::from(main_current[1].clone().into())) * beta_challenges[1].into() + AB::ExprEF::from(main_current[1].clone().into()) * beta_challenges[2].into()) * AB::ExprEF::from(main_current[3].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[3].clone().into())) * ((alpha.into() + beta_challenges[0].into().double() + AB::ExprEF::from(main_current[0].clone().into()) * beta_challenges[1].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[3].clone().into())) + AB::ExprEF::from(main_current[3].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * beta_challenges[1].into()) * (alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * beta_challenges[1].into()) * (alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * beta_challenges[1].into()) * AB::ExprEF::from(aux_current[1].clone().into()) + (alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * beta_challenges[1].into()) * (alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * beta_challenges[1].into()) * AB::ExprEF::from(main_current[4].clone().into()) + (alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * beta_challenges[1].into()) * (alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * beta_challenges[1].into()) * AB::ExprEF::from(main_current[5].clone().into()) - ((alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * beta_challenges[1].into()) * (alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * beta_challenges[1].into()) * (alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[1].clone().into()) * beta_challenges[1].into()) * AB::ExprEF::from(aux_next[1].clone().into()) + (alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * beta_challenges[1].into()) * (alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from(main_current[0].clone().into()) * beta_challenges[1].into()) * AB::ExprEF::from(main_current[6].clone().into()))); } } diff --git a/air-script/src/tests/buses/buses_simple_plonky3.rs b/air-script/src/tests/buses/buses_simple_plonky3.rs index 04e55d352..6dedb41f3 100644 --- a/air-script/src/tests/buses/buses_simple_plonky3.rs +++ b/air-script/src/tests/buses/buses_simple_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_ALPHA_CHALLENGES: usize = 2; +pub const NUM_BETA_CHALLENGES: usize = 2; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { @@ -45,8 +45,8 @@ impl> AirScriptAir for BusesAir { main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); - let beta = builder.beta(); + let alpha = builder.alpha(); + let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -64,8 +64,8 @@ impl> AirScriptAir for BusesAir { builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); // Aux integrity/transition constraints - builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) + AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); - builder.when_transition().assert_zero_ext((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()).double())); + builder.when_transition().assert_zero_ext(((alpha.into() + beta_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) + AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()).double())); } } diff --git a/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs b/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs index 04e55d352..6dedb41f3 100644 --- a/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs +++ b/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_ALPHA_CHALLENGES: usize = 2; +pub const NUM_BETA_CHALLENGES: usize = 2; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { @@ -45,8 +45,8 @@ impl> AirScriptAir for BusesAir { main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); - let beta = builder.beta(); + let alpha = builder.alpha(); + let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -64,8 +64,8 @@ impl> AirScriptAir for BusesAir { builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); // Aux integrity/transition constraints - builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) + AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); - builder.when_transition().assert_zero_ext((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()).double())); + builder.when_transition().assert_zero_ext(((alpha.into() + beta_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) + AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()).double())); } } diff --git a/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs index 765c24ca9..3addda110 100644 --- a/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 6; -pub const NUM_ALPHA_CHALLENGES: usize = 2; +pub const NUM_BETA_CHALLENGES: usize = 2; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { @@ -45,8 +45,8 @@ impl> AirScriptAir for BusesAir { main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); - let beta = builder.beta(); + let alpha = builder.alpha(); + let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -64,8 +64,8 @@ impl> AirScriptAir for BusesAir { builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into()) - aux_bus_boundary_values[1].into()); // Aux integrity/transition constraints - builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into()) * (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE) + AB::ExprEF::ONE - (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE)) * AB::ExprEF::from(aux_next[0].clone().into())); - builder.when_transition().assert_zero_ext((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()).double())); + builder.when_transition().assert_zero_ext(((alpha.into() + beta_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into()) * (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE) + AB::ExprEF::ONE - (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE)) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()).double())); } } diff --git a/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs index 686ba6582..4c41f101b 100644 --- a/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_ALPHA_CHALLENGES: usize = 2; +pub const NUM_BETA_CHALLENGES: usize = 2; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { @@ -45,8 +45,8 @@ impl> AirScriptAir for BusesAir { main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); - let beta = builder.beta(); + let alpha = builder.alpha(); + let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -65,8 +65,8 @@ impl> AirScriptAir for BusesAir { builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); // Aux integrity/transition constraints - builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into()) * (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE) + AB::ExprEF::ONE - (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE)) * AB::ExprEF::from(aux_next[0].clone().into())); - builder.when_transition().assert_zero_ext((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()).double())); + builder.when_transition().assert_zero_ext(((alpha.into() + beta_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into()) * (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE) + AB::ExprEF::ONE - (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE)) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()).double())); } } diff --git a/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs index b381f0dcf..6208c4633 100644 --- a/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_ALPHA_CHALLENGES: usize = 2; +pub const NUM_BETA_CHALLENGES: usize = 2; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { @@ -45,8 +45,8 @@ impl> AirScriptAir for BusesAir { main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); - let beta = builder.beta(); + let alpha = builder.alpha(); + let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -65,8 +65,8 @@ impl> AirScriptAir for BusesAir { builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into()) - aux_bus_boundary_values[1].into()); // Aux integrity/transition constraints - builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into()) * (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE) + AB::ExprEF::ONE - (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE)) * AB::ExprEF::from(aux_next[0].clone().into())); - builder.when_transition().assert_zero_ext((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()).double())); + builder.when_transition().assert_zero_ext(((alpha.into() + beta_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into()) * (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE) + AB::ExprEF::ONE - (AB::ExprEF::from(main_current[0].clone().into()) - AB::ExprEF::ONE)) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()).double())); } } diff --git a/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs b/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs index 004a28231..abf251210 100644 --- a/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs +++ b/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct ComputedIndicesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ComputedIndi AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs b/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs index f9427c8a4..7057a77b9 100644 --- a/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs +++ b/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct ComputedIndicesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ComputedIndi AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs b/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs index 26fe443f6..93697d96b 100644 --- a/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs +++ b/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct ConstantInRangeAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ConstantInRa AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/constants/constants_plonky3.rs b/air-script/src/tests/constants/constants_plonky3.rs index 83e3bd4a5..e066b34f9 100644 --- a/air-script/src/tests/constants/constants_plonky3.rs +++ b/air-script/src/tests/constants/constants_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 32; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct ConstantsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ConstantsAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs b/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs index 5d08db73c..7f5dc5ca3 100644 --- a/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs +++ b/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct ConstraintComprehensionAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ConstraintCo AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/evaluators/evaluators_plonky3.rs b/air-script/src/tests/evaluators/evaluators_plonky3.rs index 481e87758..5e6cb11ed 100644 --- a/air-script/src/tests/evaluators/evaluators_plonky3.rs +++ b/air-script/src/tests/evaluators/evaluators_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct EvaluatorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for EvaluatorsAi AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/fibonacci/fibonacci_plonky3.rs b/air-script/src/tests/fibonacci/fibonacci_plonky3.rs index 7bd59a684..8a6f0db8d 100644 --- a/air-script/src/tests/fibonacci/fibonacci_plonky3.rs +++ b/air-script/src/tests/fibonacci/fibonacci_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 3; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct FibonacciAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for FibonacciAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/functions/functions_complex_plonky3.rs b/air-script/src/tests/functions/functions_complex_plonky3.rs index 089a72eb2..7ce152f7b 100644 --- a/air-script/src/tests/functions/functions_complex_plonky3.rs +++ b/air-script/src/tests/functions/functions_complex_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct FunctionsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for FunctionsAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/functions/functions_simple_plonky3.rs b/air-script/src/tests/functions/functions_simple_plonky3.rs index 75151732c..6641b55b9 100644 --- a/air-script/src/tests/functions/functions_simple_plonky3.rs +++ b/air-script/src/tests/functions/functions_simple_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct FunctionsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for FunctionsAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs b/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs index 35046650a..38b33fdbc 100644 --- a/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs +++ b/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct TraceAccessAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for TraceAccessA AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs b/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs index de5ed76ba..d424e6b9d 100644 --- a/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs +++ b/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct ListComprehensionAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ListComprehe AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs b/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs index 321df1434..f5eb9bf76 100644 --- a/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs +++ b/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct ListComprehensionAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ListComprehe AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/list_folding/list_folding_plonky3.rs b/air-script/src/tests/list_folding/list_folding_plonky3.rs index bc2e5add9..b632d98d6 100644 --- a/air-script/src/tests/list_folding/list_folding_plonky3.rs +++ b/air-script/src/tests/list_folding/list_folding_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct ListFoldingAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ListFoldingA AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs b/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs index 766e8777a..e6074b0ed 100644 --- a/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs +++ b/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 2; pub const PERIOD: usize = 8; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct PeriodicColumnsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for PeriodicColu AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs b/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs index 2e71940bd..102be6493 100644 --- a/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs +++ b/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 32; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct PubInputsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for PubInputsAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs index c13d91769..687edeb73 100644 --- a/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 1; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_ALPHA_CHALLENGES: usize = 2; +pub const NUM_BETA_CHALLENGES: usize = 2; pub struct SelectorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SelectorsAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { @@ -45,8 +45,8 @@ impl> AirScriptAir for SelectorsAir main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect("Wrong number of alpha challenges"); - let beta = builder.beta(); + let alpha = builder.alpha(); + let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -67,7 +67,7 @@ impl> AirScriptAir for SelectorsAir builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); // Aux integrity/transition constraints - builder.when_transition().assert_zero_ext(((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into()) * AB::ExprEF::from(main_current[5].clone().into())) * ((beta.into() + alpha_challenges[0].into() + alpha_challenges[1].into().double()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(main_current[1].clone().into()) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::ONE - (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(main_current[1].clone().into()) * AB::ExprEF::from(main_current[5].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((beta.into() + AB::ExprEF::from_u64(3) * alpha_challenges[0].into() + AB::ExprEF::from_u64(4) * alpha_challenges[1].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[1].clone().into())) * AB::ExprEF::from(main_current[4].clone().into()) + AB::ExprEF::ONE - (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[1].clone().into())) * AB::ExprEF::from(main_current[4].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); + builder.when_transition().assert_zero_ext(((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into()) * AB::ExprEF::from(main_current[5].clone().into())) * ((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(main_current[1].clone().into()) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::ONE - (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(main_current[1].clone().into()) * AB::ExprEF::from(main_current[5].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((alpha.into() + AB::ExprEF::from_u64(3) * beta_challenges[0].into() + AB::ExprEF::from_u64(4) * beta_challenges[1].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[1].clone().into())) * AB::ExprEF::from(main_current[4].clone().into()) + AB::ExprEF::ONE - (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[1].clone().into())) * AB::ExprEF::from(main_current[4].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); } } diff --git a/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs index 31550cd79..ae00361bd 100644 --- a/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct SelectorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SelectorsAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs index 06cb94909..66f6865d4 100644 --- a/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct SelectorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SelectorsAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/selectors/selectors_plonky3.rs b/air-script/src/tests/selectors/selectors_plonky3.rs index 0a1ac04d0..f25a46ca7 100644 --- a/air-script/src/tests/selectors/selectors_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct SelectorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SelectorsAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs b/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs index 38fb17709..2e640aa2d 100644 --- a/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct SelectorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SelectorsAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/system/system_plonky3.rs b/air-script/src/tests/system/system_plonky3.rs index 5eed1e2c0..36fa3b8e9 100644 --- a/air-script/src/tests/system/system_plonky3.rs +++ b/air-script/src/tests/system/system_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct SystemAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SystemAir { AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs b/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs index 10154bb14..80b5c5bbb 100644 --- a/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs +++ b/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct TraceColGroupAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for TraceColGrou AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/variables/variables_plonky3.rs b/air-script/src/tests/variables/variables_plonky3.rs index ea20548c9..897806fbe 100644 --- a/air-script/src/tests/variables/variables_plonky3.rs +++ b/air-script/src/tests/variables/variables_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 1; pub const PERIOD: usize = 8; pub const NUM_PUBLIC_VALUES: usize = 32; -pub const NUM_ALPHA_CHALLENGES: usize = 0; +pub const NUM_BETA_CHALLENGES: usize = 0; pub struct VariablesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for VariablesAir AUX_WIDTH } - fn num_alpha_challenges(&self) -> usize { - NUM_ALPHA_CHALLENGES + fn num_beta_challenges(&self) -> usize { + NUM_BETA_CHALLENGES } fn periodic_table(&self) -> Vec> { diff --git a/codegen/plonky3/src/air/graph.rs b/codegen/plonky3/src/air/graph.rs index 72d623e09..37a5abb5b 100644 --- a/codegen/plonky3/src/air/graph.rs +++ b/codegen/plonky3/src/air/graph.rs @@ -90,9 +90,9 @@ impl Codegen for Value { }, Value::RandomValue(idx) => { if *idx == 0 { - format!("beta.into()") + format!("alpha.into()") } else { - format!("alpha_challenges[{}].into()", idx - 1) + format!("beta_challenges[{}].into()", idx - 1) } }, } diff --git a/codegen/plonky3/src/air/mod.rs b/codegen/plonky3/src/air/mod.rs index 7f4bc3270..7900310cb 100644 --- a/codegen/plonky3/src/air/mod.rs +++ b/codegen/plonky3/src/air/mod.rs @@ -46,7 +46,7 @@ fn add_constants(scope: &mut Scope, ir: &Air) { let period = ir.periodic_columns().map(|col| col.period()).max().unwrap_or(0); let num_public_values = ir.public_inputs().map(|public_input| public_input.size()).sum::(); - let num_alpha_challenges = ir.num_random_values.saturating_sub(1); + let num_beta_challenges = ir.num_random_values.saturating_sub(1); let constants = [ format!("pub const MAIN_WIDTH: usize = {main_width};"), @@ -54,7 +54,7 @@ fn add_constants(scope: &mut Scope, ir: &Air) { format!("pub const NUM_PERIODIC_VALUES: usize = {num_periodic_values};"), format!("pub const PERIOD: usize = {period};"), format!("pub const NUM_PUBLIC_VALUES: usize = {num_public_values};"), - format!("pub const NUM_ALPHA_CHALLENGES: usize = {num_alpha_challenges};"), + format!("pub const NUM_BETA_CHALLENGES: usize = {num_beta_challenges};"), ]; scope.raw(constants.join("\n")); @@ -94,12 +94,12 @@ fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { .ret("usize") .line("AUX_WIDTH"); - // add the num_alpha_challenges function + // add the num_beta_challenges function air_script_impl - .new_fn("num_alpha_challenges") + .new_fn("num_beta_challenges") .arg_ref_self() .ret("usize") - .line("NUM_ALPHA_CHALLENGES"); + .line("NUM_BETA_CHALLENGES"); // add the periodic_table function let periodic_table_func = @@ -131,8 +131,8 @@ fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { // Only had aux if there are random values if ir.num_random_values > 0 { - eval_func.line("let alpha_challenges: [_; NUM_ALPHA_CHALLENGES] = builder.alpha_powers().try_into().expect(\"Wrong number of alpha challenges\");"); - eval_func.line("let beta = builder.beta();"); + eval_func.line("let alpha = builder.alpha();"); + eval_func.line("let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect(\"Wrong number of beta challenges\");"); eval_func.line("let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect(\"Wrong number of aux bus boundary values\");"); eval_func.line("let aux = builder.permutation();"); eval_func.line("let (aux_current, aux_next) = ("); From 94df5228520dcc060bc5d0e724ab78cb5285d56b Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Wed, 12 Nov 2025 13:04:29 +0200 Subject: [PATCH 13/22] fix: Use slash for unix path in `scripts/generate_all_e2e_tests.sh` Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- scripts/generate_all_e2e_tests.sh | 48 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/scripts/generate_all_e2e_tests.sh b/scripts/generate_all_e2e_tests.sh index b27c6fe0c..55bd59ef3 100644 --- a/scripts/generate_all_e2e_tests.sh +++ b/scripts/generate_all_e2e_tests.sh @@ -8,30 +8,30 @@ cargo build --release # Winterfell Backend -./target/release/airc transpile --target winterfell .\air-script\src\tests\binary\binary.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\bitwise\bitwise.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_complex.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_simple.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_simple_with_evaluators.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_varlen_boundary_both.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_varlen_boundary_last.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\buses\buses_varlen_boundary_first.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\constant_in_range\constant_in_range.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\constants\constants.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\constraint_comprehension\constraint_comprehension.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\evaluators\evaluators.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\fibonacci\fibonacci.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\functions\functions_simple.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\functions\functions_complex.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\indexed_trace_access\indexed_trace_access.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\list_comprehension\list_comprehension_nested.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\list_comprehension\list_comprehension.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\list_folding\list_folding.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\periodic_columns\periodic_columns.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\pub_inputs\pub_inputs.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors_combine_complex.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors_combine_simple.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors_combine_with_list_comprehensions.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/binary/binary.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/bitwise/bitwise.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/buses/buses_complex.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/buses/buses_simple.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/buses/buses_simple_with_evaluators.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/buses/buses_varlen_boundary_both.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/buses/buses_varlen_boundary_last.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/buses/buses_varlen_boundary_first.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/constant_in_range/constant_in_range.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/constants/constants.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/constraint_comprehension/constraint_comprehension.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/evaluators/evaluators.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/fibonacci/fibonacci.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/functions/functions_simple.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/functions/functions_complex.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/indexed_trace_access/indexed_trace_access.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/list_comprehension/list_comprehension_nested.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/list_comprehension/list_comprehension.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/list_folding/list_folding.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/periodic_columns/periodic_columns.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/pub_inputs/pub_inputs.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/selectors/selectors_combine_complex.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/selectors/selectors_combine_simple.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/selectors/selectors_combine_with_list_comprehensions.air ./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors_with_evaluators.air ./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors.air ./target/release/airc transpile --target winterfell .\air-script\src\tests\system\system.air From b4c3cda282eb81b06e2f423289bded30f77868f4 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Wed, 12 Nov 2025 12:07:04 +0100 Subject: [PATCH 14/22] fix: Change all the backslash.. --- scripts/generate_all_e2e_tests.sh | 72 +++++++++++++++---------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/scripts/generate_all_e2e_tests.sh b/scripts/generate_all_e2e_tests.sh index 55bd59ef3..b0808b9ec 100644 --- a/scripts/generate_all_e2e_tests.sh +++ b/scripts/generate_all_e2e_tests.sh @@ -32,41 +32,41 @@ cargo build --release ./target/release/airc transpile --target winterfell ./air-script/src/tests/selectors/selectors_combine_complex.air ./target/release/airc transpile --target winterfell ./air-script/src/tests/selectors/selectors_combine_simple.air ./target/release/airc transpile --target winterfell ./air-script/src/tests/selectors/selectors_combine_with_list_comprehensions.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors_with_evaluators.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\selectors\selectors.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\system\system.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\trace_col_groups\trace_col_groups.air -./target/release/airc transpile --target winterfell .\air-script\src\tests\variables\variables.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/selectors/selectors_with_evaluators.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/selectors/selectors.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/system/system.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/trace_col_groups/trace_col_groups.air +./target/release/airc transpile --target winterfell ./air-script/src/tests/variables/variables.air # Plonky3 Backend -./target/release/airc transpile --target plonky3 .\air-script\src\tests\binary\binary.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\bitwise\bitwise.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_complex.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_simple.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_simple_with_evaluators.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_varlen_boundary_both.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_varlen_boundary_last.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\buses\buses_varlen_boundary_first.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\computed_indices\computed_indices_complex.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\computed_indices\computed_indices_simple.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\constant_in_range\constant_in_range.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\constants\constants.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\constraint_comprehension\constraint_comprehension.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\evaluators\evaluators.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\fibonacci\fibonacci.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\functions\functions_simple.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\functions\functions_complex.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\indexed_trace_access\indexed_trace_access.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\list_comprehension\list_comprehension_nested.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\list_comprehension\list_comprehension.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\list_folding\list_folding.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\periodic_columns\periodic_columns.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\pub_inputs\pub_inputs.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\selectors\selectors_combine_complex.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\selectors\selectors_combine_simple.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\selectors\selectors_combine_with_list_comprehensions.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\selectors\selectors_with_evaluators.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\selectors\selectors.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\system\system.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\trace_col_groups\trace_col_groups.air -./target/release/airc transpile --target plonky3 .\air-script\src\tests\variables\variables.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/binary/binary.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/bitwise/bitwise.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/buses/buses_complex.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/buses/buses_simple.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/buses/buses_simple_with_evaluators.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/buses/buses_varlen_boundary_both.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/buses/buses_varlen_boundary_last.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/buses/buses_varlen_boundary_first.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/computed_indices/computed_indices_complex.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/computed_indices/computed_indices_simple.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/constant_in_range/constant_in_range.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/constants/constants.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/constraint_comprehension/constraint_comprehension.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/evaluators/evaluators.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/fibonacci/fibonacci.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/functions/functions_simple.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/functions/functions_complex.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/indexed_trace_access/indexed_trace_access.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/list_comprehension/list_comprehension_nested.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/list_comprehension/list_comprehension.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/list_folding/list_folding.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/periodic_columns/periodic_columns.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/pub_inputs/pub_inputs.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/selectors/selectors_combine_complex.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/selectors/selectors_combine_simple.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/selectors/selectors_combine_with_list_comprehensions.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/selectors/selectors_with_evaluators.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/selectors/selectors.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/system/system.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/trace_col_groups/trace_col_groups.air +./target/release/airc transpile --target plonky3 ./air-script/src/tests/variables/variables.air From d09e0ff807625cc53a31d9272012a4860900cfc6 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 13 Nov 2025 12:18:16 +0100 Subject: [PATCH 15/22] chore: remove unneeded print --- air-script/src/test_utils/plonky3_traits.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/air-script/src/test_utils/plonky3_traits.rs b/air-script/src/test_utils/plonky3_traits.rs index b5ee08c0d..aacb34548 100644 --- a/air-script/src/test_utils/plonky3_traits.rs +++ b/air-script/src/test_utils/plonky3_traits.rs @@ -346,8 +346,6 @@ pub(crate) fn check_constraints_with_airscript_traits( RowMajorMatrixView::new_row(&aux_next), ); - println!("Evaluating aux current row {}: {:?}", i, aux_local); - let mut builder = DebugConstraintBuilderWithAirScriptTraits { row_index: i, main, From 5f2f35187ff40e7995c15bb2ddde9c9bb5625055 Mon Sep 17 00:00:00 2001 From: Thybault Alabarbe Date: Thu, 27 Nov 2025 15:45:36 +0100 Subject: [PATCH 16/22] tweak: Only use extension field of degree 2 for testing --- air-script/src/test_utils/air_tester_macros.rs | 2 +- air-script/src/test_utils/plonky3_traits.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/air-script/src/test_utils/air_tester_macros.rs b/air-script/src/test_utils/air_tester_macros.rs index f2352b243..12418187c 100644 --- a/air-script/src/test_utils/air_tester_macros.rs +++ b/air-script/src/test_utils/air_tester_macros.rs @@ -41,7 +41,7 @@ macro_rules! generate_air_plonky3_test_with_airscript_traits { #[test] fn $test_name() { type Val = Goldilocks; - type Challenge = BinomialExtensionField; + type Challenge = BinomialExtensionField; type ByteHash = Sha256; type FieldHash = SerializingHasher; diff --git a/air-script/src/test_utils/plonky3_traits.rs b/air-script/src/test_utils/plonky3_traits.rs index aacb34548..c86f42a15 100644 --- a/air-script/src/test_utils/plonky3_traits.rs +++ b/air-script/src/test_utils/plonky3_traits.rs @@ -306,7 +306,7 @@ pub(crate) fn check_constraints_with_airscript_traits( let height = main.height(); let aux_bus_boundary_values: Vec<_> = (0..air.aux_width()).map(|_| EF::GENERATOR).collect(); - let alpha_f: Vec = (0..5).map(|i| F::from_u64(123456789 * i)).collect(); // Dummy alpha in F + let alpha_f: Vec = (0..2).map(|i| F::from_u64(123456789 * i)).collect(); // Dummy alpha in F let alpha = EF::from_basis_coefficients_iter(alpha_f.iter().cloned()).unwrap(); let beta = EF::from_u64(987654321); let beta_powers: Vec = (0..air.num_beta_challenges()) From 06cd71e85203a160dc6ca672c92b960803e1bdd9 Mon Sep 17 00:00:00 2001 From: Thybault Alabarbe Date: Thu, 27 Nov 2025 16:05:56 +0100 Subject: [PATCH 17/22] docs: comment num_beta_challenges --- air-script/src/test_utils/plonky3_traits.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/air-script/src/test_utils/plonky3_traits.rs b/air-script/src/test_utils/plonky3_traits.rs index c86f42a15..a910fe025 100644 --- a/air-script/src/test_utils/plonky3_traits.rs +++ b/air-script/src/test_utils/plonky3_traits.rs @@ -15,7 +15,9 @@ pub trait AirScriptAir> { 0 } - /// Number of beta challenges used in the AIR. + /// Maximum number of beta challenge powers needed. + /// This number corresponds to the largest tuple of Field elements + /// that are inserted into/removed from a bus. fn num_beta_challenges(&self) -> usize { 0 } From 871058c395f0936b57f2583fc23928960b99f74b Mon Sep 17 00:00:00 2001 From: Thybault Alabarbe Date: Thu, 27 Nov 2025 16:26:38 +0100 Subject: [PATCH 18/22] refactor: rename num_beta_challenges -> max_beta_challenge_power --- air-script/src/test_utils/plonky3_traits.rs | 4 +- air-script/src/tests/binary/binary_plonky3.rs | 6 +- .../src/tests/bitwise/bitwise_plonky3.rs | 6 +- .../src/tests/buses/buses_complex_plonky3.rs | 8 +- .../src/tests/buses/buses_simple_plonky3.rs | 8 +- .../buses_simple_with_evaluators_plonky3.rs | 80 +++++++++++++------ .../buses_varlen_boundary_both_plonky3.rs | 8 +- .../buses_varlen_boundary_first_plonky3.rs | 8 +- .../buses_varlen_boundary_last_plonky3.rs | 8 +- .../computed_indices_complex_plonky3.rs | 6 +- .../computed_indices_simple_plonky3.rs | 6 +- .../constant_in_range_plonky3.rs | 6 +- .../src/tests/constants/constants_plonky3.rs | 6 +- .../constraint_comprehension_plonky3.rs | 6 +- .../tests/evaluators/evaluators_plonky3.rs | 6 +- .../src/tests/fibonacci/fibonacci_plonky3.rs | 6 +- .../functions/functions_complex_plonky3.rs | 6 +- .../functions/functions_simple_plonky3.rs | 6 +- .../indexed_trace_access_plonky3.rs | 6 +- .../list_comprehension_nested_plonky3.rs | 6 +- .../list_comprehension_plonky3.rs | 6 +- .../list_folding/list_folding_plonky3.rs | 6 +- .../periodic_columns_plonky3.rs | 6 +- .../tests/pub_inputs/pub_inputs_plonky3.rs | 6 +- .../selectors_combine_complex_plonky3.rs | 8 +- .../selectors_combine_simple_plonky3.rs | 6 +- ...ombine_with_list_comprehensions_plonky3.rs | 6 +- .../src/tests/selectors/selectors_plonky3.rs | 6 +- .../selectors_with_evaluators_plonky3.rs | 6 +- air-script/src/tests/system/system_plonky3.rs | 6 +- .../trace_col_groups_plonky3.rs | 6 +- .../src/tests/variables/variables_plonky3.rs | 6 +- codegen/plonky3/src/air/mod.rs | 12 +-- 33 files changed, 160 insertions(+), 128 deletions(-) diff --git a/air-script/src/test_utils/plonky3_traits.rs b/air-script/src/test_utils/plonky3_traits.rs index a910fe025..932b8da4b 100644 --- a/air-script/src/test_utils/plonky3_traits.rs +++ b/air-script/src/test_utils/plonky3_traits.rs @@ -18,7 +18,7 @@ pub trait AirScriptAir> { /// Maximum number of beta challenge powers needed. /// This number corresponds to the largest tuple of Field elements /// that are inserted into/removed from a bus. - fn num_beta_challenges(&self) -> usize { + fn max_beta_challenge_power(&self) -> usize { 0 } @@ -311,7 +311,7 @@ pub(crate) fn check_constraints_with_airscript_traits( let alpha_f: Vec = (0..2).map(|i| F::from_u64(123456789 * i)).collect(); // Dummy alpha in F let alpha = EF::from_basis_coefficients_iter(alpha_f.iter().cloned()).unwrap(); let beta = EF::from_u64(987654321); - let beta_powers: Vec = (0..air.num_beta_challenges()) + let beta_powers: Vec = (0..air.max_beta_challenge_power()) .map(|power| alpha.exp_u64(power as u64)) .collect(); let mut permutation_randomness = Vec::with_capacity(1 + beta_powers.len()); diff --git a/air-script/src/tests/binary/binary_plonky3.rs b/air-script/src/tests/binary/binary_plonky3.rs index 29dde9c4b..dea7bb4ed 100644 --- a/air-script/src/tests/binary/binary_plonky3.rs +++ b/air-script/src/tests/binary/binary_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct BinaryAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BinaryAir { AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/bitwise/bitwise_plonky3.rs b/air-script/src/tests/bitwise/bitwise_plonky3.rs index cf07625ab..5c4a8e7b1 100644 --- a/air-script/src/tests/bitwise/bitwise_plonky3.rs +++ b/air-script/src/tests/bitwise/bitwise_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 2; pub const PERIOD: usize = 8; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct BitwiseAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BitwiseAir { AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/buses/buses_complex_plonky3.rs b/air-script/src/tests/buses/buses_complex_plonky3.rs index 1e2a83fe7..455851000 100644 --- a/air-script/src/tests/buses/buses_complex_plonky3.rs +++ b/air-script/src/tests/buses/buses_complex_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_BETA_CHALLENGES: usize = 3; +pub const MAX_BETA_CHALLENGE_POWER: usize = 3; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { @@ -46,7 +46,7 @@ impl> AirScriptAir for BusesAir { main.row_slice(1).unwrap(), ); let alpha = builder.alpha(); - let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( diff --git a/air-script/src/tests/buses/buses_simple_plonky3.rs b/air-script/src/tests/buses/buses_simple_plonky3.rs index 6dedb41f3..433b50b98 100644 --- a/air-script/src/tests/buses/buses_simple_plonky3.rs +++ b/air-script/src/tests/buses/buses_simple_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_BETA_CHALLENGES: usize = 2; +pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { @@ -46,7 +46,7 @@ impl> AirScriptAir for BusesAir { main.row_slice(1).unwrap(), ); let alpha = builder.alpha(); - let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( diff --git a/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs b/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs index 6dedb41f3..7ad2d398f 100644 --- a/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs +++ b/air-script/src/tests/buses/buses_simple_with_evaluators_plonky3.rs @@ -1,14 +1,14 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; -use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_air::{Air, AirBuilder, BaseAir, BaseAirWithPublicValues, ExtensionBuilder}; +use p3_field::{Field, PrimeCharacteristicRing}; +use p3_matrix::Matrix; pub const MAIN_WIDTH: usize = 1; pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_BETA_CHALLENGES: usize = 2; +pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_powers(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { @@ -38,34 +38,65 @@ impl> AirScriptAir for BusesAir { } fn eval(&self, builder: &mut AB) { - let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); - let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let public_values: [_; NUM_PUBLIC_VALUES] = + builder.public_values().try_into().expect("Wrong number of public values"); + let periodic_values: [_; NUM_PERIODIC_VALUES] = + builder.periodic_evals().try_into().expect("Wrong number of periodic values"); let main = builder.main(); - let (main_current, main_next) = ( - main.row_slice(0).unwrap(), - main.row_slice(1).unwrap(), - ); + let (main_current, main_next) = (main.row_slice(0).unwrap(), main.row_slice(1).unwrap()); let alpha = builder.alpha(); - let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); - let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = + builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let aux_bus_boundary_values: [_; AUX_WIDTH] = builder + .aux_bus_boundary_values() + .try_into() + .expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); - let (aux_current, aux_next) = ( - aux.row_slice(0).unwrap(), - aux.row_slice(1).unwrap(), - ); + let (aux_current, aux_next) = (aux.row_slice(0).unwrap(), aux.row_slice(1).unwrap()); // Main boundary constraints // Main integrity/transition constraints // Aux boundary constraints - builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); - builder.when_first_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); - builder.when_last_row().assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + builder + .when_last_row() + .assert_zero_ext(AB::ExprEF::from(aux_current[0].clone().into()) - AB::ExprEF::ONE); + builder + .when_first_row() + .assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); + builder + .when_last_row() + .assert_zero_ext(AB::ExprEF::from(aux_current[1].clone().into())); // Aux integrity/transition constraints - builder.when_transition().assert_zero_ext(((alpha.into() + beta_challenges[0].into()) * AB::ExprEF::from(main_current[0].clone().into()) + AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into()) * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) + AB::ExprEF::from(main_current[0].clone().into())) * AB::ExprEF::from(aux_next[0].clone().into())); - builder.when_transition().assert_zero_ext((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_current[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(main_current[0].clone().into()) - ((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) * AB::ExprEF::from(aux_next[1].clone().into()) + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()).double())); + builder.when_transition().assert_zero_ext( + ((alpha.into() + beta_challenges[0].into()) + * AB::ExprEF::from(main_current[0].clone().into()) + + AB::ExprEF::ONE + - AB::ExprEF::from(main_current[0].clone().into())) + * AB::ExprEF::from(aux_current[0].clone().into()) + - ((alpha.into() + beta_challenges[0].into()) + * (AB::ExprEF::ONE - AB::ExprEF::from(main_current[0].clone().into())) + + AB::ExprEF::from(main_current[0].clone().into())) + * AB::ExprEF::from(aux_next[0].clone().into()), + ); + builder.when_transition().assert_zero_ext( + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) + * (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) + * AB::ExprEF::from(aux_current[1].clone().into()) + + (alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) + * AB::ExprEF::from(main_current[0].clone().into()) + - ((alpha.into() + beta_challenges[0].into() + beta_challenges[1].into().double()) + * (alpha.into() + + beta_challenges[0].into() + + beta_challenges[1].into().double()) + * AB::ExprEF::from(aux_next[1].clone().into()) + + (alpha.into() + + beta_challenges[0].into() + + beta_challenges[1].into().double()) + .double()), + ); } } @@ -73,4 +104,5 @@ impl Air for BusesAir { fn eval(&self, builder: &mut AB) { >::eval(self, builder); } -} \ No newline at end of file +} + diff --git a/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs index 3addda110..52caff9ef 100644 --- a/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 6; -pub const NUM_BETA_CHALLENGES: usize = 2; +pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { @@ -46,7 +46,7 @@ impl> AirScriptAir for BusesAir { main.row_slice(1).unwrap(), ); let alpha = builder.alpha(); - let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( diff --git a/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs index 4c41f101b..e461d601f 100644 --- a/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_BETA_CHALLENGES: usize = 2; +pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { @@ -46,7 +46,7 @@ impl> AirScriptAir for BusesAir { main.row_slice(1).unwrap(), ); let alpha = builder.alpha(); - let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( diff --git a/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs index 6208c4633..2f961e0f8 100644 --- a/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 2; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 2; -pub const NUM_BETA_CHALLENGES: usize = 2; +pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct BusesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for BusesAir { AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { @@ -46,7 +46,7 @@ impl> AirScriptAir for BusesAir { main.row_slice(1).unwrap(), ); let alpha = builder.alpha(); - let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( diff --git a/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs b/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs index abf251210..dc838030b 100644 --- a/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs +++ b/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ComputedIndicesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ComputedIndi AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs b/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs index 7057a77b9..b72de016d 100644 --- a/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs +++ b/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ComputedIndicesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ComputedIndi AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs b/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs index 93697d96b..68cf82be9 100644 --- a/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs +++ b/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ConstantInRangeAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ConstantInRa AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/constants/constants_plonky3.rs b/air-script/src/tests/constants/constants_plonky3.rs index e066b34f9..32f96a7ac 100644 --- a/air-script/src/tests/constants/constants_plonky3.rs +++ b/air-script/src/tests/constants/constants_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 32; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ConstantsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ConstantsAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs b/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs index 7f5dc5ca3..ef6c1e72f 100644 --- a/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs +++ b/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ConstraintComprehensionAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ConstraintCo AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/evaluators/evaluators_plonky3.rs b/air-script/src/tests/evaluators/evaluators_plonky3.rs index 5e6cb11ed..9aa086eee 100644 --- a/air-script/src/tests/evaluators/evaluators_plonky3.rs +++ b/air-script/src/tests/evaluators/evaluators_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct EvaluatorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for EvaluatorsAi AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/fibonacci/fibonacci_plonky3.rs b/air-script/src/tests/fibonacci/fibonacci_plonky3.rs index 8a6f0db8d..433c9e2cc 100644 --- a/air-script/src/tests/fibonacci/fibonacci_plonky3.rs +++ b/air-script/src/tests/fibonacci/fibonacci_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 3; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct FibonacciAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for FibonacciAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/functions/functions_complex_plonky3.rs b/air-script/src/tests/functions/functions_complex_plonky3.rs index 7ce152f7b..10453b9fb 100644 --- a/air-script/src/tests/functions/functions_complex_plonky3.rs +++ b/air-script/src/tests/functions/functions_complex_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct FunctionsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for FunctionsAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/functions/functions_simple_plonky3.rs b/air-script/src/tests/functions/functions_simple_plonky3.rs index 6641b55b9..2a5db958a 100644 --- a/air-script/src/tests/functions/functions_simple_plonky3.rs +++ b/air-script/src/tests/functions/functions_simple_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct FunctionsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for FunctionsAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs b/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs index 38b33fdbc..04e335da0 100644 --- a/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs +++ b/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct TraceAccessAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for TraceAccessA AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs b/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs index d424e6b9d..9e7ac0e50 100644 --- a/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs +++ b/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ListComprehensionAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ListComprehe AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs b/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs index f5eb9bf76..424bd76a3 100644 --- a/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs +++ b/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ListComprehensionAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ListComprehe AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/list_folding/list_folding_plonky3.rs b/air-script/src/tests/list_folding/list_folding_plonky3.rs index b632d98d6..4fbf81f57 100644 --- a/air-script/src/tests/list_folding/list_folding_plonky3.rs +++ b/air-script/src/tests/list_folding/list_folding_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ListFoldingAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for ListFoldingA AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs b/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs index e6074b0ed..d74208a59 100644 --- a/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs +++ b/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 2; pub const PERIOD: usize = 8; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct PeriodicColumnsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for PeriodicColu AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs b/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs index 102be6493..e1643dd10 100644 --- a/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs +++ b/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 32; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct PubInputsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for PubInputsAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs index 687edeb73..ada569c95 100644 --- a/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 1; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_BETA_CHALLENGES: usize = 2; +pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct SelectorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SelectorsAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { @@ -46,7 +46,7 @@ impl> AirScriptAir for SelectorsAir main.row_slice(1).unwrap(), ); let alpha = builder.alpha(); - let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( diff --git a/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs index ae00361bd..74849eca0 100644 --- a/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct SelectorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SelectorsAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs index 66f6865d4..e86fa64d4 100644 --- a/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 1; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct SelectorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SelectorsAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/selectors/selectors_plonky3.rs b/air-script/src/tests/selectors/selectors_plonky3.rs index f25a46ca7..1a00e1f17 100644 --- a/air-script/src/tests/selectors/selectors_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct SelectorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SelectorsAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs b/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs index 2e640aa2d..fa6bb3a35 100644 --- a/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct SelectorsAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SelectorsAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/system/system_plonky3.rs b/air-script/src/tests/system/system_plonky3.rs index 36fa3b8e9..ee5fadc25 100644 --- a/air-script/src/tests/system/system_plonky3.rs +++ b/air-script/src/tests/system/system_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct SystemAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for SystemAir { AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs b/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs index 80b5c5bbb..39fb9ff02 100644 --- a/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs +++ b/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 0; pub const PERIOD: usize = 0; pub const NUM_PUBLIC_VALUES: usize = 16; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct TraceColGroupAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for TraceColGrou AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/air-script/src/tests/variables/variables_plonky3.rs b/air-script/src/tests/variables/variables_plonky3.rs index 897806fbe..d093f71de 100644 --- a/air-script/src/tests/variables/variables_plonky3.rs +++ b/air-script/src/tests/variables/variables_plonky3.rs @@ -8,7 +8,7 @@ pub const AUX_WIDTH: usize = 0; pub const NUM_PERIODIC_VALUES: usize = 1; pub const PERIOD: usize = 8; pub const NUM_PUBLIC_VALUES: usize = 32; -pub const NUM_BETA_CHALLENGES: usize = 0; +pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct VariablesAir; @@ -29,8 +29,8 @@ impl> AirScriptAir for VariablesAir AUX_WIDTH } - fn num_beta_challenges(&self) -> usize { - NUM_BETA_CHALLENGES + fn max_beta_challenge_power(&self) -> usize { + MAX_BETA_CHALLENGE_POWER } fn periodic_table(&self) -> Vec> { diff --git a/codegen/plonky3/src/air/mod.rs b/codegen/plonky3/src/air/mod.rs index 7900310cb..13d87bc6f 100644 --- a/codegen/plonky3/src/air/mod.rs +++ b/codegen/plonky3/src/air/mod.rs @@ -46,7 +46,7 @@ fn add_constants(scope: &mut Scope, ir: &Air) { let period = ir.periodic_columns().map(|col| col.period()).max().unwrap_or(0); let num_public_values = ir.public_inputs().map(|public_input| public_input.size()).sum::(); - let num_beta_challenges = ir.num_random_values.saturating_sub(1); + let max_beta_challenge_power = ir.num_random_values.saturating_sub(1); let constants = [ format!("pub const MAIN_WIDTH: usize = {main_width};"), @@ -54,7 +54,7 @@ fn add_constants(scope: &mut Scope, ir: &Air) { format!("pub const NUM_PERIODIC_VALUES: usize = {num_periodic_values};"), format!("pub const PERIOD: usize = {period};"), format!("pub const NUM_PUBLIC_VALUES: usize = {num_public_values};"), - format!("pub const NUM_BETA_CHALLENGES: usize = {num_beta_challenges};"), + format!("pub const MAX_BETA_CHALLENGE_POWER: usize = {max_beta_challenge_power};"), ]; scope.raw(constants.join("\n")); @@ -94,12 +94,12 @@ fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { .ret("usize") .line("AUX_WIDTH"); - // add the num_beta_challenges function + // add the max_beta_challenge_power function air_script_impl - .new_fn("num_beta_challenges") + .new_fn("max_beta_challenge_power") .arg_ref_self() .ret("usize") - .line("NUM_BETA_CHALLENGES"); + .line("MAX_BETA_CHALLENGE_POWER"); // add the periodic_table function let periodic_table_func = @@ -132,7 +132,7 @@ fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { // Only had aux if there are random values if ir.num_random_values > 0 { eval_func.line("let alpha = builder.alpha();"); - eval_func.line("let beta_challenges: [_; NUM_BETA_CHALLENGES] = builder.beta_powers().try_into().expect(\"Wrong number of beta challenges\");"); + eval_func.line("let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect(\"Wrong number of beta challenges\");"); eval_func.line("let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect(\"Wrong number of aux bus boundary values\");"); eval_func.line("let aux = builder.permutation();"); eval_func.line("let (aux_current, aux_next) = ("); From 7f02a2a7de2d1d0e26fd7ab8c4a13d68353530c7 Mon Sep 17 00:00:00 2001 From: Thybault Alabarbe Date: Thu, 27 Nov 2025 16:42:02 +0100 Subject: [PATCH 19/22] docs: comment tweak + added TODOs --- air-script/src/test_utils/plonky3_traits.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/air-script/src/test_utils/plonky3_traits.rs b/air-script/src/test_utils/plonky3_traits.rs index 932b8da4b..bc1a79a82 100644 --- a/air-script/src/test_utils/plonky3_traits.rs +++ b/air-script/src/test_utils/plonky3_traits.rs @@ -37,21 +37,22 @@ where { /// EF evaluations of periodic columns at the AIR’s random point (z). Order defined by /// AirScript. + /// TODO: clarify usage of (z) here. fn periodic_evals(&self) -> &[::VarEF]; - /// Global challenges in EF. (We can provide defaults; details not important here.) + /// Global challenges in EF. fn alpha(&self) -> ::VarEF; fn beta(&self) -> ::VarEF; fn beta_powers(&self) -> &[::VarEF]; - /// Aux bus boundary values: EF finals, one per aux/bus column, carried in the proof. + /// Auxiliary buses boundary values, one per bus column, attached to the proof. fn aux_bus_boundary_values(&self) -> &[::VarEF]; } /// A builder that runs constraint assertions during testing. /// -/// Used in conjunction with [`check_constraints`] to simulate -/// an execution trace and verify that the AIR logic enforces all constraints. +/// Used in conjunction with [`check_constraints`] to simulate an execution trace +/// and verify that the AIR logic enforces all constraints. #[derive(Debug)] pub struct DebugConstraintBuilderWithAirScriptTraits<'a, F: Field, EF: ExtensionField> { /// The index of the row currently being evaluated. @@ -292,6 +293,7 @@ where let logup_next = (a * logup_current + b + c - e) * d.inverse(); // Dummy implementation for illustration purposes. + // TODO: replace with actual aux transition logic. [multiset_next, logup_next] } From 1d144757d2e193937ab366de85ba7802e18ac4d5 Mon Sep 17 00:00:00 2001 From: Thybault Alabarbe Date: Thu, 27 Nov 2025 16:49:18 +0100 Subject: [PATCH 20/22] refactor: avoid leaking extension field degree --- air-script/src/test_utils/plonky3_traits.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/air-script/src/test_utils/plonky3_traits.rs b/air-script/src/test_utils/plonky3_traits.rs index bc1a79a82..ed48dc977 100644 --- a/air-script/src/test_utils/plonky3_traits.rs +++ b/air-script/src/test_utils/plonky3_traits.rs @@ -310,8 +310,10 @@ pub(crate) fn check_constraints_with_airscript_traits( let height = main.height(); let aux_bus_boundary_values: Vec<_> = (0..air.aux_width()).map(|_| EF::GENERATOR).collect(); - let alpha_f: Vec = (0..2).map(|i| F::from_u64(123456789 * i)).collect(); // Dummy alpha in F - let alpha = EF::from_basis_coefficients_iter(alpha_f.iter().cloned()).unwrap(); + let alpha = EF::from_basis_coefficients_iter( + (0..EF::DIMENSION).map(|i| F::from_u64(123456789 * (i as u64 + 1))), + ) + .unwrap(); let beta = EF::from_u64(987654321); let beta_powers: Vec = (0..air.max_beta_challenge_power()) .map(|power| alpha.exp_u64(power as u64)) From bdcd45d93d28e83aa1573e9a6557ef5b3cb16537 Mon Sep 17 00:00:00 2001 From: Thybault Alabarbe Date: Thu, 27 Nov 2025 17:19:28 +0100 Subject: [PATCH 21/22] chores: make lint --- air-script/src/test_utils/plonky3_traits.rs | 68 ++++++++++----------- codegen/plonky3/src/air/graph.rs | 10 +-- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/air-script/src/test_utils/plonky3_traits.rs b/air-script/src/test_utils/plonky3_traits.rs index ed48dc977..d39628ad0 100644 --- a/air-script/src/test_utils/plonky3_traits.rs +++ b/air-script/src/test_utils/plonky3_traits.rs @@ -223,73 +223,69 @@ where // p' * multiset_removals = p * multiset_inserts let multiset_inserts: EF = ((alpha + beta_challenges[0] - + (EF::from_u64(3) + EF::from(main_current[1].clone())) * beta_challenges[1] - + EF::from(main_current[0].clone()) * beta_challenges[2]) - * EF::from(main_current[2].clone()) + + (EF::from_u64(3) + EF::from(main_current[1])) * beta_challenges[1] + + EF::from(main_current[0]) * beta_challenges[2]) + * EF::from(main_current[2]) + EF::ONE - - EF::from(main_current[2].clone())) - * ((alpha - + beta_challenges[0].double() - + EF::from(main_current[1].clone()) * beta_challenges[1]) - * (EF::ONE - EF::from(main_current[2].clone())) - + EF::from(main_current[2].clone())); + - EF::from(main_current[2])) + * ((alpha + beta_challenges[0].double() + EF::from(main_current[1]) * beta_challenges[1]) + * (EF::ONE - EF::from(main_current[2])) + + EF::from(main_current[2])); let multiset_removals: EF = ((alpha + beta_challenges[0] - + (EF::from_u64(3) + EF::from(main_current[1].clone())) * beta_challenges[1] - + EF::from(main_current[1].clone()) * beta_challenges[2]) - * EF::from(main_current[3].clone()) + + (EF::from_u64(3) + EF::from(main_current[1])) * beta_challenges[1] + + EF::from(main_current[1]) * beta_challenges[2]) + * EF::from(main_current[3]) + EF::ONE - - EF::from(main_current[3].clone())) - * ((alpha - + beta_challenges[0].double() - + EF::from(main_current[0].clone()) * beta_challenges[1]) - * (EF::ONE - EF::from(main_current[3].clone())) - + EF::from(main_current[3].clone())); - let multiset_current = EF::from(aux_current[0].clone()); + - EF::from(main_current[3])) + * ((alpha + beta_challenges[0].double() + EF::from(main_current[0]) * beta_challenges[1]) + * (EF::ONE - EF::from(main_current[3])) + + EF::from(main_current[3])); + let multiset_current = aux_current[0]; let multiset_next = multiset_current * multiset_inserts * multiset_removals.inverse(); // Second bus: logup // 0 = A * q + B + C - D * q' - E; let a: EF = (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0].clone()) * beta_challenges[1]) + + EF::from(main_current[0]) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0].clone()) * beta_challenges[1]) + + EF::from(main_current[0]) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[1].clone()) * beta_challenges[1]); + + EF::from(main_current[1]) * beta_challenges[1]); let b: EF = (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0].clone()) * beta_challenges[1]) + + EF::from(main_current[0]) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[1].clone()) * beta_challenges[1]) - * EF::from(main_current[4].clone()); + + EF::from(main_current[1]) * beta_challenges[1]) + * EF::from(main_current[4]); let c: EF = (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0].clone()) * beta_challenges[1]) + + EF::from(main_current[0]) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[1].clone()) * beta_challenges[1]) - * EF::from(main_current[5].clone()); + + EF::from(main_current[1]) * beta_challenges[1]) + * EF::from(main_current[5]); let d: EF = (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0].clone()) * beta_challenges[1]) + + EF::from(main_current[0]) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0].clone()) * beta_challenges[1]) + + EF::from(main_current[0]) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[1].clone()) * beta_challenges[1]); + + EF::from(main_current[1]) * beta_challenges[1]); let e: EF = (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0].clone()) * beta_challenges[1]) + + EF::from(main_current[0]) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0].clone()) * beta_challenges[1]) - * EF::from(main_current[6].clone()); - let logup_current = EF::from(aux_current[1].clone()); + + EF::from(main_current[0]) * beta_challenges[1]) + * EF::from(main_current[6]); + let logup_current = aux_current[1]; let logup_next = (a * logup_current + b + c - e) * d.inverse(); // Dummy implementation for illustration purposes. @@ -324,7 +320,7 @@ pub(crate) fn check_constraints_with_airscript_traits( let initial_aux = [EF::ONE, EF::ZERO]; - let mut current_aux_values = initial_aux.clone(); + let mut current_aux_values = initial_aux; (0..height).for_each(|i| { let i_next = (i + 1) % height; diff --git a/codegen/plonky3/src/air/graph.rs b/codegen/plonky3/src/air/graph.rs index 37a5abb5b..58a0309e7 100644 --- a/codegen/plonky3/src/air/graph.rs +++ b/codegen/plonky3/src/air/graph.rs @@ -54,12 +54,12 @@ impl Codegen for Value { fn to_string(&self, ir: &Air, elem_type: ElemType) -> String { match self { Value::Constant(0) => match elem_type { - ElemType::Base => format!("AB::Expr::ZERO"), - ElemType::Ext => format!("AB::ExprEF::ZERO"), + ElemType::Base => "AB::Expr::ZERO".to_string(), + ElemType::Ext => "AB::ExprEF::ZERO".to_string(), }, Value::Constant(1) => match elem_type { - ElemType::Base => format!("AB::Expr::ONE"), - ElemType::Ext => format!("AB::ExprEF::ONE"), + ElemType::Base => "AB::Expr::ONE".to_string(), + ElemType::Ext => "AB::ExprEF::ONE".to_string(), }, Value::Constant(value) => match elem_type { ElemType::Base => format!("AB::Expr::from_u64({value})"), @@ -90,7 +90,7 @@ impl Codegen for Value { }, Value::RandomValue(idx) => { if *idx == 0 { - format!("alpha.into()") + "alpha.into()".to_string() } else { format!("beta_challenges[{}].into()", idx - 1) } From a2bcabd49dae4fb46fb05bc58a0031b3348d9f19 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 4 Dec 2025 16:04:41 +0100 Subject: [PATCH 22/22] Use Plonky3 super trait (#515) --- .github/workflows/book.yml | 2 +- CHANGELOG.md | 1 + air-script/Cargo.toml | 32 ++- .../src/test_utils/air_tester_macros.rs | 43 +-- .../miden_vm_aux_trace_generator.rs | 116 ++++++++ air-script/src/test_utils/mod.rs | 4 +- air-script/src/test_utils/plonky3_traits.rs | 266 +++--------------- air-script/src/tests/binary/binary_plonky3.rs | 40 +-- .../src/tests/binary/test_air_plonky3.rs | 15 +- .../src/tests/bitwise/bitwise_plonky3.rs | 49 ++-- air-script/src/tests/bitwise/mod.rs | 1 + .../src/tests/bitwise/test_air_plonky3.rs | 15 +- .../src/tests/buses/buses_complex_plonky3.rs | 100 +++++-- .../src/tests/buses/buses_simple_plonky3.rs | 99 +++++-- .../buses_varlen_boundary_both_plonky3.rs | 100 +++++-- .../buses_varlen_boundary_first_plonky3.rs | 100 +++++-- .../buses_varlen_boundary_last_plonky3.rs | 100 +++++-- .../src/tests/buses/test_air_plonky3.rs | 15 +- .../computed_indices_complex_plonky3.rs | 40 +-- .../computed_indices_simple_plonky3.rs | 40 +-- .../computed_indices/test_air_plonky3.rs | 15 +- .../constant_in_range_plonky3.rs | 40 +-- .../constant_in_range/test_air_plonky3.rs | 15 +- .../src/tests/constants/constants_plonky3.rs | 40 +-- .../src/tests/constants/test_air_plonky3.rs | 15 +- .../constraint_comprehension_plonky3.rs | 40 +-- .../test_air_plonky3.rs | 15 +- .../tests/evaluators/evaluators_plonky3.rs | 40 +-- .../src/tests/evaluators/test_air_plonky3.rs | 15 +- .../src/tests/fibonacci/fibonacci_plonky3.rs | 40 +-- .../src/tests/fibonacci/test_air_plonky3.rs | 15 +- .../functions/functions_complex_plonky3.rs | 40 +-- .../functions/functions_simple_plonky3.rs | 40 +-- .../src/tests/functions/test_air_plonky3.rs | 15 +- .../indexed_trace_access_plonky3.rs | 40 +-- .../indexed_trace_access/test_air_plonky3.rs | 15 +- .../list_comprehension_nested_plonky3.rs | 40 +-- .../list_comprehension_plonky3.rs | 40 +-- .../list_comprehension/test_air_plonky3.rs | 15 +- .../list_folding/list_folding_plonky3.rs | 40 +-- .../tests/list_folding/test_air_plonky3.rs | 15 +- .../periodic_columns_plonky3.rs | 39 +-- .../periodic_columns/test_air_plonky3.rs | 15 +- .../tests/pub_inputs/pub_inputs_plonky3.rs | 40 +-- .../src/tests/pub_inputs/test_air_plonky3.rs | 15 +- .../selectors_combine_complex_plonky3.rs | 98 +++++-- .../selectors_combine_simple_plonky3.rs | 40 +-- ...ombine_with_list_comprehensions_plonky3.rs | 40 +-- .../src/tests/selectors/selectors_plonky3.rs | 40 +-- .../selectors_with_evaluators_plonky3.rs | 40 +-- .../src/tests/selectors/test_air_plonky3.rs | 15 +- air-script/src/tests/system/system_plonky3.rs | 40 +-- .../src/tests/system/test_air_plonky3.rs | 15 +- .../trace_col_groups/test_air_plonky3.rs | 15 +- .../trace_col_groups_plonky3.rs | 40 +-- .../src/tests/variables/test_air_plonky3.rs | 15 +- .../src/tests/variables/variables_plonky3.rs | 37 +-- air/src/ir/mod.rs | 16 +- .../common_subexpression_elimination.rs | 22 ++ air/src/passes/expand_buses.rs | 33 +++ codegen/plonky3/src/air/graph.rs | 34 ++- codegen/plonky3/src/air/mod.rs | 211 ++++++++++---- codegen/plonky3/src/imports.rs | 15 +- 63 files changed, 1210 insertions(+), 1433 deletions(-) create mode 100644 air-script/src/test_utils/miden_vm_aux_trace_generator.rs diff --git a/.github/workflows/book.yml b/.github/workflows/book.yml index 8dbe014b7..10a5fdede 100644 --- a/.github/workflows/book.yml +++ b/.github/workflows/book.yml @@ -42,7 +42,7 @@ jobs: - name: Install mdbook and plugins uses: taiki-e/install-action@v2 with: - tool: mdbook, mdbook-linkcheck, mdbook-alerts, mdbook-katex, mdbook-mermaid + tool: mdbook@0.4.48, mdbook-linkcheck, mdbook-alerts, mdbook-katex, mdbook-mermaid - name: Build book run: mdbook build docs/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 59d55ecc9..364bc9045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Add Plonky3 codegen backend (#461). - Fixed a vector unrolling issue in nested match evaluations (#491). - In Plonky3 codegen, use AirScriptAir and AirScriptBuilder traits, and generate aux constraints (#508). +- In Plonky3 codegen, use MidenAir and MidenAirBuilder from 0xMiden's Plonky3 fork instead of AirScriptAir and AirScriptBuilder (#515). ## 0.4.0 (2025-06-20) diff --git a/air-script/Cargo.toml b/air-script/Cargo.toml index 25a265f82..65813db4e 100644 --- a/air-script/Cargo.toml +++ b/air-script/Cargo.toml @@ -30,18 +30,26 @@ mir = { package = "air-mir", path = "../mir", version = "0.5" } [dev-dependencies] expect-test = "1.4" -p3-air = { package = "p3-air", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-challenger = { package = "p3-challenger", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-circle = { package = "p3-circle", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-commit = { package = "p3-commit", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-field = { package = "p3-field", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-fri = { package = "p3-fri", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-matrix = { package = "p3-matrix", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-merkle-tree = { package = "p3-merkle-tree", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-goldilocks = { package = "p3-goldilocks", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-sha256 = { package = "p3-sha256", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-symmetric = { package = "p3-symmetric", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } -p3-uni-stark = { package = "p3-uni-stark", git="https://github.com/0xMiden/Plonky3", rev = "2e6ff23090b5bd5138695ceb757181443a523c6d", default-features = false } + +# 0xMiden Plonky3 Fork +p3-air = { package = "p3-air", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-challenger = { package = "p3-challenger", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-commit = { package = "p3-commit", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-dft = { package = "p3-dft", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-field = { package = "p3-field", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-fri = { package = "p3-fri", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-matrix = { package = "p3-matrix", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-merkle-tree = { package = "p3-merkle-tree", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-miden-air = { package = "miden-air", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-goldilocks = { package = "p3-goldilocks", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-sha256 = { package = "p3-sha256", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-symmetric = { package = "p3-symmetric", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } +p3-uni-stark = { package = "p3-uni-stark", git="https://github.com/0xMiden/Plonky3", rev = "5352d47ee57bd1b5d6008a90b64cbb7fe00aa17e", default-features = false } + +# MassaLabs fork +miden-processor = { package = "miden-processor", git="https://github.com/massalabs/miden-vm", rev = "bc553af69a2543a0789830e8508b019694528181", default-features = false } +miden-air = { package = "miden-air", git="https://github.com/massalabs/miden-vm", rev = "bc553af69a2543a0789830e8508b019694528181", default-features = false } + winter-air = { package = "winter-air", version = "0.12", default-features = false } winter-math = { package = "winter-math", version = "0.12", default-features = false } winter-utils = { package = "winter-utils", version = "0.12", default-features = false } diff --git a/air-script/src/test_utils/air_tester_macros.rs b/air-script/src/test_utils/air_tester_macros.rs index 12418187c..53a64784e 100644 --- a/air-script/src/test_utils/air_tester_macros.rs +++ b/air-script/src/test_utils/air_tester_macros.rs @@ -40,38 +40,41 @@ macro_rules! generate_air_plonky3_test_with_airscript_traits { ($test_name:ident, $air_name:ident) => { #[test] fn $test_name() { - type Val = Goldilocks; - type Challenge = BinomialExtensionField; - - type ByteHash = Sha256; - type FieldHash = SerializingHasher; - type MyCompress = CompressionFunctionFromHasher; - type ValMmcs = MerkleTreeMmcs; - type ChallengeMmcs = ExtensionMmcs; - type Challenger = SerializingChallenger64>; - type Pcs = CirclePcs; - type MyConfig = StarkConfig; + type Val = p3_goldilocks::Goldilocks; + type Challenge = p3_field::extension::BinomialExtensionField; + type ByteHash = p3_sha256::Sha256; + type FieldHash = p3_symmetric::SerializingHasher; + type MyCompress = p3_symmetric::CompressionFunctionFromHasher; + type ValMmcs = p3_merkle_tree::MerkleTreeMmcs; + type ChallengeMmcs = p3_commit::ExtensionMmcs; + type Challenger = p3_challenger::SerializingChallenger64< + Val, + p3_challenger::HashChallenger, + >; + type Dft = p3_dft::Radix2DitParallel; + type Pcs = p3_fri::TwoAdicFriPcs; + type MyConfig = p3_uni_stark::StarkConfig; let byte_hash = ByteHash {}; - let field_hash = FieldHash::new(Sha256); + let field_hash = FieldHash::new(p3_sha256::Sha256); let compress = MyCompress::new(byte_hash); let val_mmcs = ValMmcs::new(field_hash, compress); let challenge_mmcs = ChallengeMmcs::new(val_mmcs.clone()); let challenger = Challenger::from_hasher(vec![], byte_hash); - let fri_params = create_benchmark_fri_params(challenge_mmcs); - let pcs = Pcs { - mmcs: val_mmcs, - fri_params, - _phantom: PhantomData, - }; + let dft = Dft::default(); + let fri_params = p3_fri::create_benchmark_fri_params(challenge_mmcs); + let pcs = Pcs::new(dft, val_mmcs, fri_params); let config = MyConfig::new(pcs, challenger); let inputs = generate_inputs(); - let inputs_goldilocks: Vec = inputs.iter().map(|&x| Val::from_u32(x)).collect(); + let inputs_goldilocks: Vec = inputs + .iter() + .map(|&x| ::from_u32(x)) + .collect(); let trace = generate_trace_rows::(inputs); - check_constraints_with_airscript_traits::( + check_constraints_with_airscript_traits::( &$air_name {}, &trace, &inputs_goldilocks, diff --git a/air-script/src/test_utils/miden_vm_aux_trace_generator.rs b/air-script/src/test_utils/miden_vm_aux_trace_generator.rs new file mode 100644 index 000000000..a6f9517c1 --- /dev/null +++ b/air-script/src/test_utils/miden_vm_aux_trace_generator.rs @@ -0,0 +1,116 @@ +use std::collections::BTreeMap; + +use miden_air::{Felt, FieldElement, trace::main_trace::MainTrace}; +use miden_processor::{ + ColMatrix, Kernel, PrecompileTranscriptState, QuadExtension, + chiplets::{AceHints, AuxTraceBuilder as ChipletsAuxTraceBuilder}, + decoder::AuxTraceBuilder as DecoderAuxTraceBuilder, + range::AuxTraceBuilder as RangeAuxTraceBuilder, + stack::AuxTraceBuilder as StackAuxTraceBuilder, +}; +use p3_field::{ExtensionField, Field, PrimeField64}; +use p3_matrix::Matrix; +use p3_miden_air::RowMajorMatrix; + +pub enum MidenModule { + Chiplets, + Decoder, + Stack, + Range, +} + +impl MidenModule { + fn build_aux_columns>( + &self, + main_trace: &MainTrace, + rand_elements: &[EF], + ) -> Vec> { + match self { + MidenModule::Chiplets => { + let kernel = Kernel::new(&[]).unwrap(); + let ace_hints = AceHints::new(0, vec![]); + let final_transcript_state = PrecompileTranscriptState::default(); + let aux_trace_builder = + ChipletsAuxTraceBuilder::new(kernel, ace_hints, final_transcript_state); + aux_trace_builder.build_aux_columns(main_trace, rand_elements).to_vec() + }, + MidenModule::Decoder => { + let aux_trace_builder = DecoderAuxTraceBuilder {}; + aux_trace_builder.build_aux_columns(main_trace, rand_elements) + }, + MidenModule::Stack => { + let aux_trace_builder = StackAuxTraceBuilder {}; + aux_trace_builder.build_aux_columns(main_trace, rand_elements) + }, + MidenModule::Range => { + let lookup_values = vec![]; + let cycle_lookups = BTreeMap::new(); + let values_start = 0; + let aux_trace_builder = + RangeAuxTraceBuilder::new(lookup_values, cycle_lookups, values_start); + aux_trace_builder.build_aux_columns(main_trace, rand_elements) + }, + } + } +} + +/// Builds the Miden VM auxiliary trace using the provided main trace and challenges. +pub fn build_aux_trace_with_miden_vm( + main: &RowMajorMatrix, + challenges: &[EF], + module: MidenModule, +) -> RowMajorMatrix +where + F: Field + PrimeField64, + EF: ExtensionField, +{ + // Convert main trace to Miden format: transposed to column-major and use `BaseElement` instead + // of `F`` + let main_transposed = main.transpose(); + let mut felt_columns_vec = Vec::new(); + for row in main_transposed.rows() { + let col_felt = row.map(|x| Felt::new(x.as_canonical_u64())).collect::>(); + felt_columns_vec.push(col_felt); + } + let col_matrix = ColMatrix::new(felt_columns_vec); + let last_program_row = main.height().into(); + let main_trace = MainTrace::new(col_matrix, last_program_row); + + // Convert challenges to Miden format + let mut rand_elements = Vec::new(); + for r in challenges { + let coeffs: Vec = r + .as_basis_coefficients_slice() + .iter() + .map(|x| Felt::new(x.as_canonical_u64())) + .collect(); + let r_fe: &[QuadExtension] = FieldElement::slice_from_base_elements(&coeffs); + rand_elements.push(r_fe[0]); + } + + // Build aux trace using Miden VM AuxTraceBuilder + let aux_trace_miden = module.build_aux_columns(&main_trace, &rand_elements); + let aux_width = aux_trace_miden.len(); + + // Convert aux trace back to RowMajorMatrix + let num_rows = main.height(); + let trace_length = num_rows * aux_width; + let long_trace = EF::zero_vec(trace_length); + let mut aux_trace = RowMajorMatrix::new(long_trace, aux_width); + + for j in 0..aux_width { + let col = aux_trace_miden.get(j).unwrap(); + for i in 0..num_rows { + let value_felt = col[i]; + let coeffs_f: Vec = value_felt + .to_base_elements() + .iter() + .map(|x| F::from_canonical_checked(x.as_int()).unwrap()) + .collect(); + let value_ef = EF::from_basis_coefficients_iter(coeffs_f.iter().cloned()).unwrap(); + aux_trace.row_mut(i)[j] = value_ef; + } + } + + aux_trace +} diff --git a/air-script/src/test_utils/mod.rs b/air-script/src/test_utils/mod.rs index 1fe4b9486..601c64017 100644 --- a/air-script/src/test_utils/mod.rs +++ b/air-script/src/test_utils/mod.rs @@ -2,7 +2,9 @@ pub mod air_tester_macros; /// Code generation for tests/**/*.air files. pub mod codegen; -/// Plonky3-specific traits, to be moved to 0xMiden/Plonky3 once stabilized. +/// Miden VM auxiliary trace generator +pub mod miden_vm_aux_trace_generator; +/// Plonky3-specific Debug constraint builder implementation pub mod plonky3_traits; /// Winterfell-specific traits pub mod winterfell_traits; diff --git a/air-script/src/test_utils/plonky3_traits.rs b/air-script/src/test_utils/plonky3_traits.rs index d39628ad0..1985d1558 100644 --- a/air-script/src/test_utils/plonky3_traits.rs +++ b/air-script/src/test_utils/plonky3_traits.rs @@ -1,53 +1,10 @@ -use p3_air::{ - Air, AirBuilder, AirBuilderWithPublicValues, ExtensionBuilder, PermutationAirBuilder, -}; use p3_field::{ExtensionField, Field}; use p3_matrix::{ Matrix, - dense::{RowMajorMatrix, RowMajorMatrixView}, + dense::{DenseMatrix, RowMajorMatrix, RowMajorMatrixView}, stack::VerticalPair, }; - -/// Miden/AirScript-specific AIR. Replaces BaseAir for this forked target. -pub trait AirScriptAir> { - /// Auxiliary width of the AIR. - fn aux_width(&self) -> usize { - 0 - } - - /// Maximum number of beta challenge powers needed. - /// This number corresponds to the largest tuple of Field elements - /// that are inserted into/removed from a bus. - fn max_beta_challenge_power(&self) -> usize { - 0 - } - - /// Periodic constants (base-field) backing periodic_evals(). - fn periodic_table(&self) -> Vec>; - - /// Single entrypoint: encodes main + aux + boundary constraints. - fn eval(&self, builder: &mut AB); -} - -/// Target trait for AirScript codegen. Implemented by the prover. -pub trait AirScriptBuilder: - AirBuilder + AirBuilderWithPublicValues + ExtensionBuilder + PermutationAirBuilder -where - ::F: Field, -{ - /// EF evaluations of periodic columns at the AIR’s random point (z). Order defined by - /// AirScript. - /// TODO: clarify usage of (z) here. - fn periodic_evals(&self) -> &[::VarEF]; - - /// Global challenges in EF. - fn alpha(&self) -> ::VarEF; - fn beta(&self) -> ::VarEF; - fn beta_powers(&self) -> &[::VarEF]; - - /// Auxiliary buses boundary values, one per bus column, attached to the proof. - fn aux_bus_boundary_values(&self) -> &[::VarEF]; -} +use p3_miden_air::{MidenAir, MidenAirBuilder, impl_p3_air_builder_traits}; /// A builder that runs constraint assertions during testing. /// @@ -59,6 +16,8 @@ pub struct DebugConstraintBuilderWithAirScriptTraits<'a, F: Field, EF: Extension row_index: usize, /// A view of the current and next main row as a vertical pair. main: VerticalPair, RowMajorMatrixView<'a, F>>, + /// A view of the current and next preprocessed row as a vertical pair. + preprocessed: VerticalPair, RowMajorMatrixView<'a, F>>, /// A view of the current and next aux row as a vertical pair. aux: VerticalPair, RowMajorMatrixView<'a, EF>>, /// The public values provided for constraint validation (e.g. inputs or outputs). @@ -71,19 +30,13 @@ pub struct DebugConstraintBuilderWithAirScriptTraits<'a, F: Field, EF: Extension is_transition: F, /// The periodic columns provided for constraint validation. periodic_columns: Vec, - /// The alpha challenge in the extension field. - alpha: EF, - /// The beta challenge in the extension field. - beta: EF, - /// The beta powers in the extension field. - beta_powers: Vec, /// The permutation randomness in the extension field. permutation_randomness: Vec, /// The aux bus boundary values in the extension field. aux_bus_boundary_values: Vec, } -impl<'a, F, EF> AirBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> +impl<'a, F, EF> MidenAirBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> where F: Field, EF: ExtensionField, @@ -91,7 +44,14 @@ where type F = F; type Expr = F; type Var = F; - type M = VerticalPair, RowMajorMatrixView<'a, F>>; + type M = VerticalPair, DenseMatrix>; + type PublicVar = F; + type PeriodicVal = EF; + type EF = EF; + type ExprEF = EF; + type VarEF = EF; + type MP = VerticalPair, DenseMatrix>; + type RandomVar = EF; fn main(&self) -> Self::M { self.main @@ -105,8 +65,6 @@ where self.is_last_row } - /// # Panics - /// This function panics if `size` is not `2`. fn is_transition_window(&self, size: usize) -> Self::Expr { if size == 2 { self.is_transition @@ -119,35 +77,17 @@ where assert_eq!(x.into(), F::ZERO, "constraints had nonzero value on row {}", self.row_index); } - fn assert_eq, I2: Into>(&mut self, x: I1, y: I2) { - let x = x.into(); - let y = y.into(); - assert_eq!(x, y, "values didn't match on row {}: {} != {}", self.row_index, x, y); - } -} - -impl<'a, F, EF> AirBuilderWithPublicValues for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> -where - F: Field, - EF: ExtensionField, -{ - type PublicVar = Self::F; - - fn public_values(&self) -> &[Self::F] { + fn public_values(&self) -> &[Self::PublicVar] { self.public_values } -} -impl<'a, F, EF> ExtensionBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> -where - F: Field, - EF: ExtensionField, -{ - type EF = EF; - - type ExprEF = EF; + fn periodic_evals(&self) -> &[::PeriodicVal] { + self.periodic_columns.as_slice() + } - type VarEF = EF; + fn preprocessed(&self) -> Self::M { + self.preprocessed + } fn assert_zero_ext(&mut self, x: I) where @@ -160,16 +100,6 @@ where self.row_index ); } -} - -impl<'a, F, EF> PermutationAirBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> -where - F: Field, - EF: ExtensionField, -{ - type MP = VerticalPair, RowMajorMatrixView<'a, EF>>; - - type RandomVar = EF; fn permutation(&self) -> Self::MP { self.aux @@ -178,120 +108,13 @@ where fn permutation_randomness(&self) -> &[Self::RandomVar] { self.permutation_randomness.as_slice() } -} - -impl<'a, F, EF> AirScriptBuilder for DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> -where - F: Field + Into, - EF: ExtensionField, -{ - fn periodic_evals(&self) -> &[::VarEF] { - self.periodic_columns.as_slice() - } - - fn alpha(&self) -> ::VarEF { - self.alpha - } - - fn beta_powers(&self) -> &[::VarEF] { - self.beta_powers.as_slice() - } - fn beta(&self) -> ::VarEF { - self.beta - } - - fn aux_bus_boundary_values(&self) -> &[::VarEF] { + fn aux_bus_boundary_values(&self) -> &[::VarEF] { self.aux_bus_boundary_values.as_slice() } } -fn compute_aux_transition( - main: VerticalPair, RowMajorMatrixView>, - alpha: EF, - beta_challenges: Vec, - aux_current: [EF; 2], -) -> [EF; 2] -where - F: Field, - EF: ExtensionField, -{ - let main_current = &main.row_slice(0).unwrap(); - let _main_next = &main.row_slice(1).unwrap(); - - // First bus: multiset - // p' * multiset_removals = p * multiset_inserts - let multiset_inserts: EF = ((alpha - + beta_challenges[0] - + (EF::from_u64(3) + EF::from(main_current[1])) * beta_challenges[1] - + EF::from(main_current[0]) * beta_challenges[2]) - * EF::from(main_current[2]) - + EF::ONE - - EF::from(main_current[2])) - * ((alpha + beta_challenges[0].double() + EF::from(main_current[1]) * beta_challenges[1]) - * (EF::ONE - EF::from(main_current[2])) - + EF::from(main_current[2])); - let multiset_removals: EF = ((alpha - + beta_challenges[0] - + (EF::from_u64(3) + EF::from(main_current[1])) * beta_challenges[1] - + EF::from(main_current[1]) * beta_challenges[2]) - * EF::from(main_current[3]) - + EF::ONE - - EF::from(main_current[3])) - * ((alpha + beta_challenges[0].double() + EF::from(main_current[0]) * beta_challenges[1]) - * (EF::ONE - EF::from(main_current[3])) - + EF::from(main_current[3])); - let multiset_current = aux_current[0]; - let multiset_next = multiset_current * multiset_inserts * multiset_removals.inverse(); - - // Second bus: logup - // 0 = A * q + B + C - D * q' - E; - let a: EF = (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0]) * beta_challenges[1]) - * (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0]) * beta_challenges[1]) - * (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[1]) * beta_challenges[1]); - let b: EF = (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0]) * beta_challenges[1]) - * (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[1]) * beta_challenges[1]) - * EF::from(main_current[4]); - let c: EF = (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0]) * beta_challenges[1]) - * (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[1]) * beta_challenges[1]) - * EF::from(main_current[5]); - let d: EF = (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0]) * beta_challenges[1]) - * (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0]) * beta_challenges[1]) - * (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[1]) * beta_challenges[1]); - let e: EF = (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0]) * beta_challenges[1]) - * (alpha - + EF::from_u64(3) * beta_challenges[0] - + EF::from(main_current[0]) * beta_challenges[1]) - * EF::from(main_current[6]); - let logup_current = aux_current[1]; - let logup_next = (a * logup_current + b + c - e) * d.inverse(); - - // Dummy implementation for illustration purposes. - // TODO: replace with actual aux transition logic. - [multiset_next, logup_next] -} +impl_p3_air_builder_traits!(DebugConstraintBuilderWithAirScriptTraits<'a, F, EF> where F: Field, EF: ExtensionField); pub(crate) fn check_constraints_with_airscript_traits( air: &A, @@ -300,8 +123,7 @@ pub(crate) fn check_constraints_with_airscript_traits( ) where F: Field, EF: ExtensionField, - A: for<'a> Air>, - A: for<'a> AirScriptAir>, + A: MidenAir, { let height = main.height(); @@ -311,16 +133,16 @@ pub(crate) fn check_constraints_with_airscript_traits( ) .unwrap(); let beta = EF::from_u64(987654321); - let beta_powers: Vec = (0..air.max_beta_challenge_power()) - .map(|power| alpha.exp_u64(power as u64)) + let beta_powers: Vec = (0..(air.num_randomness().saturating_sub(1))) + .map(|power| beta.exp_u64(power as u64)) .collect(); - let mut permutation_randomness = Vec::with_capacity(1 + beta_powers.len()); + let mut permutation_randomness = Vec::with_capacity(air.num_randomness()); permutation_randomness.push(alpha); permutation_randomness.extend_from_slice(beta_powers.as_slice()); - let initial_aux = [EF::ONE, EF::ZERO]; - - let mut current_aux_values = initial_aux; + let aux_trace = air + .build_aux_trace(main, &permutation_randomness) + .unwrap_or(DenseMatrix::default(0, height)); (0..height).for_each(|i| { let i_next = (i + 1) % height; @@ -331,39 +153,37 @@ pub(crate) fn check_constraints_with_airscript_traits( RowMajorMatrixView::new_row(&*main_local), RowMajorMatrixView::new_row(&*main_next), ); + let aux_local_ref = aux_trace.row_slice(i); + let aux_next_ref = aux_trace.row_slice(i_next); + let aux_local = aux_local_ref.as_deref().unwrap_or_default(); + let aux_next = aux_next_ref.as_deref().unwrap_or_default(); + let aux = VerticalPair::new( + RowMajorMatrixView::new_row(&*aux_local), + RowMajorMatrixView::new_row(&*aux_next), + ); + let preprocessed = VerticalPair::new::( + RowMajorMatrixView::new(&[], 0), + RowMajorMatrixView::new(&[], 0), + ); let periodic_columns_base: Vec<_> = air.periodic_table().iter().map(|col| col[i % col.len()]).collect(); let periodic_columns: Vec = periodic_columns_base.iter().map(|&v| EF::from(v)).collect(); - let aux_local = current_aux_values; - if air.aux_width() > 0 && i != height - 1 { - current_aux_values = - compute_aux_transition::(main, alpha, beta_powers.clone(), aux_local); - } - let aux_next = current_aux_values; - let aux = VerticalPair::new( - RowMajorMatrixView::new_row(&aux_local), - RowMajorMatrixView::new_row(&aux_next), - ); - let mut builder = DebugConstraintBuilderWithAirScriptTraits { row_index: i, main, + preprocessed, aux, public_values, is_first_row: F::from_bool(i == 0), is_last_row: F::from_bool(i == height - 1), is_transition: F::from_bool(i != height - 1), periodic_columns, - alpha, - beta, - beta_powers: beta_powers.clone(), permutation_randomness: permutation_randomness.clone(), aux_bus_boundary_values: aux_bus_boundary_values.clone(), }; - - AirScriptAir::eval(air, &mut builder); + air.eval(&mut builder); }); } diff --git a/air-script/src/tests/binary/binary_plonky3.rs b/air-script/src/tests/binary/binary_plonky3.rs index dea7bb4ed..0c514ea56 100644 --- a/air-script/src/tests/binary/binary_plonky3.rs +++ b/air-script/src/tests/binary/binary_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 2; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct BinaryAir; -impl BaseAir for BinaryAir { +impl MidenAir for BinaryAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for BinaryAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for BinaryAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -57,10 +41,4 @@ impl> AirScriptAir for BinaryAir { // Aux integrity/transition constraints } -} - -impl Air for BinaryAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/binary/test_air_plonky3.rs b/air-script/src/tests/binary/test_air_plonky3.rs index c60b72a0c..eced0b469 100644 --- a/air-script/src/tests/binary/test_air_plonky3.rs +++ b/air-script/src/tests/binary/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/bitwise/bitwise_plonky3.rs b/air-script/src/tests/bitwise/bitwise_plonky3.rs index 5c4a8e7b1..bfded5b9b 100644 --- a/air-script/src/tests/bitwise/bitwise_plonky3.rs +++ b/air-script/src/tests/bitwise/bitwise_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 14; pub const AUX_WIDTH: usize = 0; @@ -12,26 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct BitwiseAir; -impl BaseAir for BitwiseAir { +impl MidenAir for BitwiseAir +where F: Field, + EF: ExtensionField, +{ fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for BitwiseAir { fn num_public_values(&self) -> usize { NUM_PUBLIC_VALUES } -} - -impl> AirScriptAir for BitwiseAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } fn periodic_table(&self) -> Vec> { vec![ @@ -40,9 +32,12 @@ impl> AirScriptAir for BitwiseAir { ] } - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -54,7 +49,7 @@ impl> AirScriptAir for BitwiseAir { // Main integrity/transition constraints builder.assert_zero(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); - builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); + builder.when_transition().assert_zero_ext(AB::ExprEF::from(periodic_values[1].clone().into()) * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); builder.assert_zero(main_current[3].clone().into() * main_current[3].clone().into() - main_current[3].clone().into()); builder.assert_zero(main_current[4].clone().into() * main_current[4].clone().into() - main_current[4].clone().into()); builder.assert_zero(main_current[5].clone().into() * main_current[5].clone().into() - main_current[5].clone().into()); @@ -63,22 +58,16 @@ impl> AirScriptAir for BitwiseAir { builder.assert_zero(main_current[8].clone().into() * main_current[8].clone().into() - main_current[8].clone().into()); builder.assert_zero(main_current[9].clone().into() * main_current[9].clone().into() - main_current[9].clone().into()); builder.assert_zero(main_current[10].clone().into() * main_current[10].clone().into() - main_current[10].clone().into()); - builder.assert_zero_ext(periodic_values[0].into() * (AB::ExprEF::from(main_current[1].clone().into()) - (AB::ExprEF::from(main_current[3].clone().into()) + AB::ExprEF::from(main_current[4].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[6].clone().into())))); - builder.assert_zero_ext(periodic_values[0].into() * (AB::ExprEF::from(main_current[2].clone().into()) - (AB::ExprEF::from(main_current[7].clone().into()) + AB::ExprEF::from(main_current[8].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[9].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[10].clone().into())))); - builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_next[1].clone().into()) - (AB::ExprEF::from(main_current[1].clone().into()) * AB::ExprEF::from_u64(16) + AB::ExprEF::from(main_current[3].clone().into()) + AB::ExprEF::from(main_current[4].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[6].clone().into())))); - builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_next[2].clone().into()) - (AB::ExprEF::from(main_current[2].clone().into()) * AB::ExprEF::from_u64(16) + AB::ExprEF::from(main_current[7].clone().into()) + AB::ExprEF::from(main_current[8].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[9].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[10].clone().into())))); - builder.assert_zero_ext(periodic_values[0].into() * AB::ExprEF::from(main_current[11].clone().into())); - builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_current[12].clone().into()) - AB::ExprEF::from(main_next[11].clone().into()))); + builder.assert_zero_ext(AB::ExprEF::from(periodic_values[0].clone().into()) * (AB::ExprEF::from(main_current[1].clone().into()) - (AB::ExprEF::from(main_current[3].clone().into()) + AB::ExprEF::from(main_current[4].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[6].clone().into())))); + builder.assert_zero_ext(AB::ExprEF::from(periodic_values[0].clone().into()) * (AB::ExprEF::from(main_current[2].clone().into()) - (AB::ExprEF::from(main_current[7].clone().into()) + AB::ExprEF::from(main_current[8].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[9].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[10].clone().into())))); + builder.when_transition().assert_zero_ext(AB::ExprEF::from(periodic_values[1].clone().into()) * (AB::ExprEF::from(main_next[1].clone().into()) - (AB::ExprEF::from(main_current[1].clone().into()) * AB::ExprEF::from_u64(16) + AB::ExprEF::from(main_current[3].clone().into()) + AB::ExprEF::from(main_current[4].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[5].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[6].clone().into())))); + builder.when_transition().assert_zero_ext(AB::ExprEF::from(periodic_values[1].clone().into()) * (AB::ExprEF::from(main_next[2].clone().into()) - (AB::ExprEF::from(main_current[2].clone().into()) * AB::ExprEF::from_u64(16) + AB::ExprEF::from(main_current[7].clone().into()) + AB::ExprEF::from(main_current[8].clone().into()).double() + AB::ExprEF::from_u64(4) * AB::ExprEF::from(main_current[9].clone().into()) + AB::ExprEF::from_u64(8) * AB::ExprEF::from(main_current[10].clone().into())))); + builder.assert_zero_ext(AB::ExprEF::from(periodic_values[0].clone().into()) * AB::ExprEF::from(main_current[11].clone().into())); + builder.when_transition().assert_zero_ext(AB::ExprEF::from(periodic_values[1].clone().into()) * (AB::ExprEF::from(main_current[12].clone().into()) - AB::ExprEF::from(main_next[11].clone().into()))); builder.assert_zero((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() * main_current[7].clone().into() + main_current[4].clone().into().double() * main_current[8].clone().into() + AB::Expr::from_u64(4) * main_current[5].clone().into() * main_current[9].clone().into() + AB::Expr::from_u64(8) * main_current[6].clone().into() * main_current[10].clone().into())) + main_current[0].clone().into() * (main_current[12].clone().into() - (main_current[11].clone().into() * AB::Expr::from_u64(16) + main_current[3].clone().into() + main_current[7].clone().into() - main_current[3].clone().into().double() * main_current[7].clone().into() + (main_current[4].clone().into() + main_current[8].clone().into() - main_current[4].clone().into().double() * main_current[8].clone().into()).double() + AB::Expr::from_u64(4) * (main_current[5].clone().into() + main_current[9].clone().into() - main_current[5].clone().into().double() * main_current[9].clone().into()) + AB::Expr::from_u64(8) * (main_current[6].clone().into() + main_current[10].clone().into() - main_current[6].clone().into().double() * main_current[10].clone().into())))); // Aux boundary constraints // Aux integrity/transition constraints } -} - -impl Air for BitwiseAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/bitwise/mod.rs b/air-script/src/tests/bitwise/mod.rs index 31fe7ab14..54b732efb 100644 --- a/air-script/src/tests/bitwise/mod.rs +++ b/air-script/src/tests/bitwise/mod.rs @@ -3,6 +3,7 @@ mod bitwise; #[rustfmt::skip] #[allow(clippy::all)] +#[allow(unused_imports)] mod bitwise_plonky3; mod test_air_plonky3; diff --git a/air-script/src/tests/bitwise/test_air_plonky3.rs b/air-script/src/tests/bitwise/test_air_plonky3.rs index 87e297ff7..d969cb1a6 100644 --- a/air-script/src/tests/bitwise/test_air_plonky3.rs +++ b/air-script/src/tests/bitwise/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/buses/buses_complex_plonky3.rs b/air-script/src/tests/buses/buses_complex_plonky3.rs index 455851000..00d266cf9 100644 --- a/air-script/src/tests/buses/buses_complex_plonky3.rs +++ b/air-script/src/tests/buses/buses_complex_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 7; pub const AUX_WIDTH: usize = 2; @@ -12,41 +13,75 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 3; pub struct BusesAir; -impl BaseAir for BusesAir { +impl MidenAir for BusesAir +where F: Field, + EF: ExtensionField, +{ fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for BusesAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES + fn num_randomness(&self) -> usize { + 1 + MAX_BETA_CHALLENGE_POWER } -} -impl> AirScriptAir for BusesAir { fn aux_width(&self) -> usize { AUX_WIDTH } - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } + fn build_aux_trace(&self, _main: &RowMajorMatrix, _challenges: &[EF]) -> Option> { + // Note: consider using Some(build_aux_trace_with_miden_vm::(_main, _challenges, module)) if you want to build the aux trace using Miden VM aux trace builders. - fn periodic_table(&self) -> Vec> { - vec![] + let num_rows = _main.height(); + let trace_length = num_rows * AUX_WIDTH; + let mut long_trace = EF::zero_vec(trace_length); + let mut trace = RowMajorMatrix::new(long_trace, AUX_WIDTH); + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[EF; AUX_WIDTH]>() }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(rows.len(), num_rows); + // Initialize first row + let initial_values = Self::buses_initial_values::(); + for j in 0..AUX_WIDTH { + rows[0][j] = initial_values[j]; + } + // Fill subsequent rows using direct access to the rows array + for i in 0..num_rows-1 { + let i_next = (i + 1) % num_rows; + let main_local = _main.row_slice(i).unwrap(); // i < height so unwrap should never fail. + let main_next = _main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail. + let main = VerticalPair::new( + RowMajorMatrixView::new_row(&*main_local), + RowMajorMatrixView::new_row(&*main_next), + ); + let periodic_values: [_; NUM_PERIODIC_VALUES] = >::periodic_table(self).iter().map(|col| col[i % col.len()]).collect::>().try_into().expect("Wrong number of periodic values"); + let prev_row = &rows[i]; + let next_row = Self::buses_transitions::( + &main, + _challenges, + &periodic_values, + prev_row, + ); + for j in 0..AUX_WIDTH { + rows[i+1][j] = next_row[j]; + } + } + Some(trace) } - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha = builder.alpha(); - let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let (&alpha, beta_challenges) = builder.permutation_randomness().split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -73,8 +108,31 @@ impl> AirScriptAir for BusesAir { } } -impl Air for BusesAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); +impl BusesAir { + fn buses_initial_values() -> Vec + where F: Field, + EF: ExtensionField, + { + vec![ + EF::ONE, + EF::ZERO, + ] + } + + fn buses_transitions(main: &VerticalPair, RowMajorMatrixView>, challenges: &[EF], periodic_evals: &[F], aux_current: &[EF]) -> Vec + where F: Field, + EF: ExtensionField, + { + let (main_current, main_next) = ( + main.row_slice(0).unwrap(), + main.row_slice(1).unwrap(), + ); + let (&alpha, beta_challenges) = challenges.split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); + let periodic_values: [_; NUM_PERIODIC_VALUES] = periodic_evals.try_into().expect("Wrong number of periodic values"); + vec![ + (((alpha + beta_challenges[0] + (EF::from_u64(3) + EF::from(main_current[1].clone())) * beta_challenges[1] + EF::from(main_current[0].clone()) * beta_challenges[2]) * EF::from(main_current[2].clone()) + EF::ONE - EF::from(main_current[2].clone())) * ((alpha + beta_challenges[0].double() + EF::from(main_current[1].clone()) * beta_challenges[1]) * (EF::ONE - EF::from(main_current[2].clone())) + EF::from(main_current[2].clone())) * EF::from(aux_current[0].clone())) * (((alpha + beta_challenges[0] + (EF::from_u64(3) + EF::from(main_current[1].clone())) * beta_challenges[1] + EF::from(main_current[1].clone()) * beta_challenges[2]) * EF::from(main_current[3].clone()) + EF::ONE - EF::from(main_current[3].clone())) * ((alpha + beta_challenges[0].double() + EF::from(main_current[0].clone()) * beta_challenges[1]) * (EF::ONE - EF::from(main_current[3].clone())) + EF::from(main_current[3].clone()))).inverse(), + ((alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[0].clone()) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[0].clone()) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[1].clone()) * beta_challenges[1]) * EF::from(aux_current[1].clone()) + (alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[0].clone()) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[1].clone()) * beta_challenges[1]) * EF::from(main_current[4].clone()) + (alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[0].clone()) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[1].clone()) * beta_challenges[1]) * EF::from(main_current[5].clone()) - (alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[0].clone()) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[0].clone()) * beta_challenges[1]) * EF::from(main_current[6].clone())) * ((alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[0].clone()) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[0].clone()) * beta_challenges[1]) * (alpha + EF::from_u64(3) * beta_challenges[0] + EF::from(main_current[1].clone()) * beta_challenges[1])).inverse(), + ] } } \ No newline at end of file diff --git a/air-script/src/tests/buses/buses_simple_plonky3.rs b/air-script/src/tests/buses/buses_simple_plonky3.rs index 433b50b98..1ee51d533 100644 --- a/air-script/src/tests/buses/buses_simple_plonky3.rs +++ b/air-script/src/tests/buses/buses_simple_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 1; pub const AUX_WIDTH: usize = 2; @@ -12,41 +13,75 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct BusesAir; -impl BaseAir for BusesAir { +impl MidenAir for BusesAir +where F: Field, + EF: ExtensionField, +{ fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for BusesAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES + fn num_randomness(&self) -> usize { + 1 + MAX_BETA_CHALLENGE_POWER } -} -impl> AirScriptAir for BusesAir { fn aux_width(&self) -> usize { AUX_WIDTH } - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } + fn build_aux_trace(&self, _main: &RowMajorMatrix, _challenges: &[EF]) -> Option> { + // Note: consider using Some(build_aux_trace_with_miden_vm::(_main, _challenges, module)) if you want to build the aux trace using Miden VM aux trace builders. - fn periodic_table(&self) -> Vec> { - vec![] + let num_rows = _main.height(); + let trace_length = num_rows * AUX_WIDTH; + let mut long_trace = EF::zero_vec(trace_length); + let mut trace = RowMajorMatrix::new(long_trace, AUX_WIDTH); + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[EF; AUX_WIDTH]>() }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(rows.len(), num_rows); + // Initialize first row + let initial_values = Self::buses_initial_values::(); + for j in 0..AUX_WIDTH { + rows[0][j] = initial_values[j]; + } + // Fill subsequent rows using direct access to the rows array + for i in 0..num_rows-1 { + let i_next = (i + 1) % num_rows; + let main_local = _main.row_slice(i).unwrap(); // i < height so unwrap should never fail. + let main_next = _main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail. + let main = VerticalPair::new( + RowMajorMatrixView::new_row(&*main_local), + RowMajorMatrixView::new_row(&*main_next), + ); + let periodic_values: [_; NUM_PERIODIC_VALUES] = >::periodic_table(self).iter().map(|col| col[i % col.len()]).collect::>().try_into().expect("Wrong number of periodic values"); + let prev_row = &rows[i]; + let next_row = Self::buses_transitions::( + &main, + _challenges, + &periodic_values, + prev_row, + ); + for j in 0..AUX_WIDTH { + rows[i+1][j] = next_row[j]; + } + } + Some(trace) } - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha = builder.alpha(); - let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let (&alpha, beta_challenges) = builder.permutation_randomness().split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -69,8 +104,30 @@ impl> AirScriptAir for BusesAir { } } -impl Air for BusesAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); +impl BusesAir { + fn buses_initial_values() -> Vec + where F: Field, + EF: ExtensionField, + { + vec![ + EF::ZERO, + ] + } + + fn buses_transitions(main: &VerticalPair, RowMajorMatrixView>, challenges: &[EF], periodic_evals: &[F], aux_current: &[EF]) -> Vec + where F: Field, + EF: ExtensionField, + { + let (main_current, main_next) = ( + main.row_slice(0).unwrap(), + main.row_slice(1).unwrap(), + ); + let (&alpha, beta_challenges) = challenges.split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); + let periodic_values: [_; NUM_PERIODIC_VALUES] = periodic_evals.try_into().expect("Wrong number of periodic values"); + vec![ + (((alpha + beta_challenges[0]) * EF::from(main_current[0].clone()) + EF::ONE - EF::from(main_current[0].clone())) * EF::from(aux_current[0].clone())) * ((alpha + beta_challenges[0]) * (EF::ONE - EF::from(main_current[0].clone())) + EF::from(main_current[0].clone())).inverse(), + ((alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(aux_current[1].clone()) + (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(main_current[0].clone()) - (alpha + beta_challenges[0] + beta_challenges[1].double()).double()) * ((alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double())).inverse(), + ] } } \ No newline at end of file diff --git a/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs index 52caff9ef..13ed74cc7 100644 --- a/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_both_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 1; pub const AUX_WIDTH: usize = 2; @@ -12,41 +13,75 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct BusesAir; -impl BaseAir for BusesAir { +impl MidenAir for BusesAir +where F: Field, + EF: ExtensionField, +{ fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for BusesAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES + fn num_randomness(&self) -> usize { + 1 + MAX_BETA_CHALLENGE_POWER } -} -impl> AirScriptAir for BusesAir { fn aux_width(&self) -> usize { AUX_WIDTH } - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } + fn build_aux_trace(&self, _main: &RowMajorMatrix, _challenges: &[EF]) -> Option> { + // Note: consider using Some(build_aux_trace_with_miden_vm::(_main, _challenges, module)) if you want to build the aux trace using Miden VM aux trace builders. - fn periodic_table(&self) -> Vec> { - vec![] + let num_rows = _main.height(); + let trace_length = num_rows * AUX_WIDTH; + let mut long_trace = EF::zero_vec(trace_length); + let mut trace = RowMajorMatrix::new(long_trace, AUX_WIDTH); + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[EF; AUX_WIDTH]>() }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(rows.len(), num_rows); + // Initialize first row + let initial_values = Self::buses_initial_values::(); + for j in 0..AUX_WIDTH { + rows[0][j] = initial_values[j]; + } + // Fill subsequent rows using direct access to the rows array + for i in 0..num_rows-1 { + let i_next = (i + 1) % num_rows; + let main_local = _main.row_slice(i).unwrap(); // i < height so unwrap should never fail. + let main_next = _main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail. + let main = VerticalPair::new( + RowMajorMatrixView::new_row(&*main_local), + RowMajorMatrixView::new_row(&*main_next), + ); + let periodic_values: [_; NUM_PERIODIC_VALUES] = >::periodic_table(self).iter().map(|col| col[i % col.len()]).collect::>().try_into().expect("Wrong number of periodic values"); + let prev_row = &rows[i]; + let next_row = Self::buses_transitions::( + &main, + _challenges, + &periodic_values, + prev_row, + ); + for j in 0..AUX_WIDTH { + rows[i+1][j] = next_row[j]; + } + } + Some(trace) } - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha = builder.alpha(); - let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let (&alpha, beta_challenges) = builder.permutation_randomness().split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -69,8 +104,31 @@ impl> AirScriptAir for BusesAir { } } -impl Air for BusesAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); +impl BusesAir { + fn buses_initial_values() -> Vec + where F: Field, + EF: ExtensionField, + { + vec![ + EF::ZERO, + EF::ZERO, + ] + } + + fn buses_transitions(main: &VerticalPair, RowMajorMatrixView>, challenges: &[EF], periodic_evals: &[F], aux_current: &[EF]) -> Vec + where F: Field, + EF: ExtensionField, + { + let (main_current, main_next) = ( + main.row_slice(0).unwrap(), + main.row_slice(1).unwrap(), + ); + let (&alpha, beta_challenges) = challenges.split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); + let periodic_values: [_; NUM_PERIODIC_VALUES] = periodic_evals.try_into().expect("Wrong number of periodic values"); + vec![ + (((alpha + beta_challenges[0]) * EF::from(main_current[0].clone()) + EF::ONE - EF::from(main_current[0].clone())) * EF::from(aux_current[0].clone())) * ((alpha + beta_challenges[0]) * (EF::from(main_current[0].clone()) - EF::ONE) + EF::ONE - (EF::from(main_current[0].clone()) - EF::ONE)).inverse(), + ((alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(aux_current[1].clone()) + (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(main_current[0].clone()) + (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(main_current[0].clone()) - (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()).double()) * ((alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double())).inverse(), + ] } } \ No newline at end of file diff --git a/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs index e461d601f..7a8c42bda 100644 --- a/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_first_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 1; pub const AUX_WIDTH: usize = 2; @@ -12,41 +13,75 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct BusesAir; -impl BaseAir for BusesAir { +impl MidenAir for BusesAir +where F: Field, + EF: ExtensionField, +{ fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for BusesAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES + fn num_randomness(&self) -> usize { + 1 + MAX_BETA_CHALLENGE_POWER } -} -impl> AirScriptAir for BusesAir { fn aux_width(&self) -> usize { AUX_WIDTH } - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } + fn build_aux_trace(&self, _main: &RowMajorMatrix, _challenges: &[EF]) -> Option> { + // Note: consider using Some(build_aux_trace_with_miden_vm::(_main, _challenges, module)) if you want to build the aux trace using Miden VM aux trace builders. - fn periodic_table(&self) -> Vec> { - vec![] + let num_rows = _main.height(); + let trace_length = num_rows * AUX_WIDTH; + let mut long_trace = EF::zero_vec(trace_length); + let mut trace = RowMajorMatrix::new(long_trace, AUX_WIDTH); + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[EF; AUX_WIDTH]>() }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(rows.len(), num_rows); + // Initialize first row + let initial_values = Self::buses_initial_values::(); + for j in 0..AUX_WIDTH { + rows[0][j] = initial_values[j]; + } + // Fill subsequent rows using direct access to the rows array + for i in 0..num_rows-1 { + let i_next = (i + 1) % num_rows; + let main_local = _main.row_slice(i).unwrap(); // i < height so unwrap should never fail. + let main_next = _main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail. + let main = VerticalPair::new( + RowMajorMatrixView::new_row(&*main_local), + RowMajorMatrixView::new_row(&*main_next), + ); + let periodic_values: [_; NUM_PERIODIC_VALUES] = >::periodic_table(self).iter().map(|col| col[i % col.len()]).collect::>().try_into().expect("Wrong number of periodic values"); + let prev_row = &rows[i]; + let next_row = Self::buses_transitions::( + &main, + _challenges, + &periodic_values, + prev_row, + ); + for j in 0..AUX_WIDTH { + rows[i+1][j] = next_row[j]; + } + } + Some(trace) } - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha = builder.alpha(); - let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let (&alpha, beta_challenges) = builder.permutation_randomness().split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -70,8 +105,31 @@ impl> AirScriptAir for BusesAir { } } -impl Air for BusesAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); +impl BusesAir { + fn buses_initial_values() -> Vec + where F: Field, + EF: ExtensionField, + { + vec![ + EF::ZERO, + EF::ZERO, + ] + } + + fn buses_transitions(main: &VerticalPair, RowMajorMatrixView>, challenges: &[EF], periodic_evals: &[F], aux_current: &[EF]) -> Vec + where F: Field, + EF: ExtensionField, + { + let (main_current, main_next) = ( + main.row_slice(0).unwrap(), + main.row_slice(1).unwrap(), + ); + let (&alpha, beta_challenges) = challenges.split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); + let periodic_values: [_; NUM_PERIODIC_VALUES] = periodic_evals.try_into().expect("Wrong number of periodic values"); + vec![ + (((alpha + beta_challenges[0]) * EF::from(main_current[0].clone()) + EF::ONE - EF::from(main_current[0].clone())) * EF::from(aux_current[0].clone())) * ((alpha + beta_challenges[0]) * (EF::from(main_current[0].clone()) - EF::ONE) + EF::ONE - (EF::from(main_current[0].clone()) - EF::ONE)).inverse(), + ((alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(aux_current[1].clone()) + (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(main_current[0].clone()) + (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(main_current[0].clone()) - (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()).double()) * ((alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double())).inverse(), + ] } } \ No newline at end of file diff --git a/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs b/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs index 2f961e0f8..fa895389e 100644 --- a/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs +++ b/air-script/src/tests/buses/buses_varlen_boundary_last_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 1; pub const AUX_WIDTH: usize = 2; @@ -12,41 +13,75 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct BusesAir; -impl BaseAir for BusesAir { +impl MidenAir for BusesAir +where F: Field, + EF: ExtensionField, +{ fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for BusesAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES + fn num_randomness(&self) -> usize { + 1 + MAX_BETA_CHALLENGE_POWER } -} -impl> AirScriptAir for BusesAir { fn aux_width(&self) -> usize { AUX_WIDTH } - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } + fn build_aux_trace(&self, _main: &RowMajorMatrix, _challenges: &[EF]) -> Option> { + // Note: consider using Some(build_aux_trace_with_miden_vm::(_main, _challenges, module)) if you want to build the aux trace using Miden VM aux trace builders. - fn periodic_table(&self) -> Vec> { - vec![] + let num_rows = _main.height(); + let trace_length = num_rows * AUX_WIDTH; + let mut long_trace = EF::zero_vec(trace_length); + let mut trace = RowMajorMatrix::new(long_trace, AUX_WIDTH); + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[EF; AUX_WIDTH]>() }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(rows.len(), num_rows); + // Initialize first row + let initial_values = Self::buses_initial_values::(); + for j in 0..AUX_WIDTH { + rows[0][j] = initial_values[j]; + } + // Fill subsequent rows using direct access to the rows array + for i in 0..num_rows-1 { + let i_next = (i + 1) % num_rows; + let main_local = _main.row_slice(i).unwrap(); // i < height so unwrap should never fail. + let main_next = _main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail. + let main = VerticalPair::new( + RowMajorMatrixView::new_row(&*main_local), + RowMajorMatrixView::new_row(&*main_next), + ); + let periodic_values: [_; NUM_PERIODIC_VALUES] = >::periodic_table(self).iter().map(|col| col[i % col.len()]).collect::>().try_into().expect("Wrong number of periodic values"); + let prev_row = &rows[i]; + let next_row = Self::buses_transitions::( + &main, + _challenges, + &periodic_values, + prev_row, + ); + for j in 0..AUX_WIDTH { + rows[i+1][j] = next_row[j]; + } + } + Some(trace) } - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha = builder.alpha(); - let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let (&alpha, beta_challenges) = builder.permutation_randomness().split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -70,8 +105,31 @@ impl> AirScriptAir for BusesAir { } } -impl Air for BusesAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); +impl BusesAir { + fn buses_initial_values() -> Vec + where F: Field, + EF: ExtensionField, + { + vec![ + EF::ONE, + EF::ZERO, + ] + } + + fn buses_transitions(main: &VerticalPair, RowMajorMatrixView>, challenges: &[EF], periodic_evals: &[F], aux_current: &[EF]) -> Vec + where F: Field, + EF: ExtensionField, + { + let (main_current, main_next) = ( + main.row_slice(0).unwrap(), + main.row_slice(1).unwrap(), + ); + let (&alpha, beta_challenges) = challenges.split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); + let periodic_values: [_; NUM_PERIODIC_VALUES] = periodic_evals.try_into().expect("Wrong number of periodic values"); + vec![ + (((alpha + beta_challenges[0]) * EF::from(main_current[0].clone()) + EF::ONE - EF::from(main_current[0].clone())) * EF::from(aux_current[0].clone())) * ((alpha + beta_challenges[0]) * (EF::from(main_current[0].clone()) - EF::ONE) + EF::ONE - (EF::from(main_current[0].clone()) - EF::ONE)).inverse(), + ((alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(aux_current[1].clone()) + (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(main_current[0].clone()) + (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(main_current[0].clone()) - (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()).double()) * ((alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double()) * (alpha + beta_challenges[0] + beta_challenges[1].double())).inverse(), + ] } } \ No newline at end of file diff --git a/air-script/src/tests/buses/test_air_plonky3.rs b/air-script/src/tests/buses/test_air_plonky3.rs index 6b818e844..20919a31e 100644 --- a/air-script/src/tests/buses/test_air_plonky3.rs +++ b/air-script/src/tests/buses/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs b/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs index dc838030b..ae3ee2903 100644 --- a/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs +++ b/air-script/src/tests/computed_indices/computed_indices_complex_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ComputedIndicesAir; -impl BaseAir for ComputedIndicesAir { +impl MidenAir for ComputedIndicesAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for ComputedIndicesAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for ComputedIndicesAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -56,10 +40,4 @@ impl> AirScriptAir for ComputedIndi // Aux integrity/transition constraints } -} - -impl Air for ComputedIndicesAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs b/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs index b72de016d..40c374ad3 100644 --- a/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs +++ b/air-script/src/tests/computed_indices/computed_indices_simple_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 8; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ComputedIndicesAir; -impl BaseAir for ComputedIndicesAir { +impl MidenAir for ComputedIndicesAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for ComputedIndicesAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for ComputedIndicesAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -63,10 +47,4 @@ impl> AirScriptAir for ComputedIndi // Aux integrity/transition constraints } -} - -impl Air for ComputedIndicesAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/computed_indices/test_air_plonky3.rs b/air-script/src/tests/computed_indices/test_air_plonky3.rs index e8eb0f244..5f02cc466 100644 --- a/air-script/src/tests/computed_indices/test_air_plonky3.rs +++ b/air-script/src/tests/computed_indices/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs b/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs index 68cf82be9..b1238f7cc 100644 --- a/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs +++ b/air-script/src/tests/constant_in_range/constant_in_range_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 12; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ConstantInRangeAir; -impl BaseAir for ConstantInRangeAir { +impl MidenAir for ConstantInRangeAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for ConstantInRangeAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for ConstantInRangeAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -56,10 +40,4 @@ impl> AirScriptAir for ConstantInRa // Aux integrity/transition constraints } -} - -impl Air for ConstantInRangeAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/constant_in_range/test_air_plonky3.rs b/air-script/src/tests/constant_in_range/test_air_plonky3.rs index 160c681bc..9dd399e1c 100644 --- a/air-script/src/tests/constant_in_range/test_air_plonky3.rs +++ b/air-script/src/tests/constant_in_range/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/constants/constants_plonky3.rs b/air-script/src/tests/constants/constants_plonky3.rs index 32f96a7ac..632331aab 100644 --- a/air-script/src/tests/constants/constants_plonky3.rs +++ b/air-script/src/tests/constants/constants_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 7; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ConstantsAir; -impl BaseAir for ConstantsAir { +impl MidenAir for ConstantsAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for ConstantsAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for ConstantsAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -65,10 +49,4 @@ impl> AirScriptAir for ConstantsAir // Aux integrity/transition constraints } -} - -impl Air for ConstantsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/constants/test_air_plonky3.rs b/air-script/src/tests/constants/test_air_plonky3.rs index 42fcdc199..cf2c54ebd 100644 --- a/air-script/src/tests/constants/test_air_plonky3.rs +++ b/air-script/src/tests/constants/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs b/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs index ef6c1e72f..e333b9626 100644 --- a/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs +++ b/air-script/src/tests/constraint_comprehension/constraint_comprehension_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 14; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ConstraintComprehensionAir; -impl BaseAir for ConstraintComprehensionAir { +impl MidenAir for ConstraintComprehensionAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for ConstraintComprehensionAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for ConstraintComprehensionAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -59,10 +43,4 @@ impl> AirScriptAir for ConstraintCo // Aux integrity/transition constraints } -} - -impl Air for ConstraintComprehensionAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/constraint_comprehension/test_air_plonky3.rs b/air-script/src/tests/constraint_comprehension/test_air_plonky3.rs index b5c290df4..f9fa0d39c 100644 --- a/air-script/src/tests/constraint_comprehension/test_air_plonky3.rs +++ b/air-script/src/tests/constraint_comprehension/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/evaluators/evaluators_plonky3.rs b/air-script/src/tests/evaluators/evaluators_plonky3.rs index 9aa086eee..07f19ea21 100644 --- a/air-script/src/tests/evaluators/evaluators_plonky3.rs +++ b/air-script/src/tests/evaluators/evaluators_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 7; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct EvaluatorsAir; -impl BaseAir for EvaluatorsAir { +impl MidenAir for EvaluatorsAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for EvaluatorsAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for EvaluatorsAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -65,10 +49,4 @@ impl> AirScriptAir for EvaluatorsAi // Aux integrity/transition constraints } -} - -impl Air for EvaluatorsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/evaluators/test_air_plonky3.rs b/air-script/src/tests/evaluators/test_air_plonky3.rs index b06040a1f..050ba860a 100644 --- a/air-script/src/tests/evaluators/test_air_plonky3.rs +++ b/air-script/src/tests/evaluators/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/fibonacci/fibonacci_plonky3.rs b/air-script/src/tests/fibonacci/fibonacci_plonky3.rs index 433c9e2cc..b5476e071 100644 --- a/air-script/src/tests/fibonacci/fibonacci_plonky3.rs +++ b/air-script/src/tests/fibonacci/fibonacci_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 2; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct FibonacciAir; -impl BaseAir for FibonacciAir { +impl MidenAir for FibonacciAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for FibonacciAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for FibonacciAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -59,10 +43,4 @@ impl> AirScriptAir for FibonacciAir // Aux integrity/transition constraints } -} - -impl Air for FibonacciAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/fibonacci/test_air_plonky3.rs b/air-script/src/tests/fibonacci/test_air_plonky3.rs index 8596f5106..1d76e60d2 100644 --- a/air-script/src/tests/fibonacci/test_air_plonky3.rs +++ b/air-script/src/tests/fibonacci/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/functions/functions_complex_plonky3.rs b/air-script/src/tests/functions/functions_complex_plonky3.rs index 10453b9fb..b42205283 100644 --- a/air-script/src/tests/functions/functions_complex_plonky3.rs +++ b/air-script/src/tests/functions/functions_complex_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 17; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct FunctionsAir; -impl BaseAir for FunctionsAir { +impl MidenAir for FunctionsAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for FunctionsAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for FunctionsAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -57,10 +41,4 @@ impl> AirScriptAir for FunctionsAir // Aux integrity/transition constraints } -} - -impl Air for FunctionsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/functions/functions_simple_plonky3.rs b/air-script/src/tests/functions/functions_simple_plonky3.rs index 2a5db958a..c5b131f49 100644 --- a/air-script/src/tests/functions/functions_simple_plonky3.rs +++ b/air-script/src/tests/functions/functions_simple_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 9; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct FunctionsAir; -impl BaseAir for FunctionsAir { +impl MidenAir for FunctionsAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for FunctionsAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for FunctionsAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -63,10 +47,4 @@ impl> AirScriptAir for FunctionsAir // Aux integrity/transition constraints } -} - -impl Air for FunctionsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/functions/test_air_plonky3.rs b/air-script/src/tests/functions/test_air_plonky3.rs index b95913e4d..f52390339 100644 --- a/air-script/src/tests/functions/test_air_plonky3.rs +++ b/air-script/src/tests/functions/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs b/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs index 04e335da0..d1f6eb420 100644 --- a/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs +++ b/air-script/src/tests/indexed_trace_access/indexed_trace_access_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct TraceAccessAir; -impl BaseAir for TraceAccessAir { +impl MidenAir for TraceAccessAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for TraceAccessAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for TraceAccessAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -56,10 +40,4 @@ impl> AirScriptAir for TraceAccessA // Aux integrity/transition constraints } -} - -impl Air for TraceAccessAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/indexed_trace_access/test_air_plonky3.rs b/air-script/src/tests/indexed_trace_access/test_air_plonky3.rs index 7c2cea5ab..4b0a31c39 100644 --- a/air-script/src/tests/indexed_trace_access/test_air_plonky3.rs +++ b/air-script/src/tests/indexed_trace_access/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs b/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs index 9e7ac0e50..734706746 100644 --- a/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs +++ b/air-script/src/tests/list_comprehension/list_comprehension_nested_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 2; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ListComprehensionAir; -impl BaseAir for ListComprehensionAir { +impl MidenAir for ListComprehensionAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for ListComprehensionAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for ListComprehensionAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -58,10 +42,4 @@ impl> AirScriptAir for ListComprehe // Aux integrity/transition constraints } -} - -impl Air for ListComprehensionAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs b/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs index 424bd76a3..727cc9cc0 100644 --- a/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs +++ b/air-script/src/tests/list_comprehension/list_comprehension_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 16; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ListComprehensionAir; -impl BaseAir for ListComprehensionAir { +impl MidenAir for ListComprehensionAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for ListComprehensionAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for ListComprehensionAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -61,10 +45,4 @@ impl> AirScriptAir for ListComprehe // Aux integrity/transition constraints } -} - -impl Air for ListComprehensionAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/list_comprehension/test_air_plonky3.rs b/air-script/src/tests/list_comprehension/test_air_plonky3.rs index 794c64267..a99c57065 100644 --- a/air-script/src/tests/list_comprehension/test_air_plonky3.rs +++ b/air-script/src/tests/list_comprehension/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/list_folding/list_folding_plonky3.rs b/air-script/src/tests/list_folding/list_folding_plonky3.rs index 4fbf81f57..1a455fdd9 100644 --- a/air-script/src/tests/list_folding/list_folding_plonky3.rs +++ b/air-script/src/tests/list_folding/list_folding_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 17; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct ListFoldingAir; -impl BaseAir for ListFoldingAir { +impl MidenAir for ListFoldingAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for ListFoldingAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for ListFoldingAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -59,10 +43,4 @@ impl> AirScriptAir for ListFoldingA // Aux integrity/transition constraints } -} - -impl Air for ListFoldingAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/list_folding/test_air_plonky3.rs b/air-script/src/tests/list_folding/test_air_plonky3.rs index 19d3ab9ed..a87dae25b 100644 --- a/air-script/src/tests/list_folding/test_air_plonky3.rs +++ b/air-script/src/tests/list_folding/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs b/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs index d74208a59..22acad484 100644 --- a/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs +++ b/air-script/src/tests/periodic_columns/periodic_columns_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 3; pub const AUX_WIDTH: usize = 0; @@ -12,26 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct PeriodicColumnsAir; -impl BaseAir for PeriodicColumnsAir { +impl MidenAir for PeriodicColumnsAir +where F: Field, + EF: ExtensionField, +{ fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for PeriodicColumnsAir { fn num_public_values(&self) -> usize { NUM_PUBLIC_VALUES } -} - -impl> AirScriptAir for PeriodicColumnsAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } fn periodic_table(&self) -> Vec> { vec![ @@ -40,9 +32,12 @@ impl> AirScriptAir for PeriodicColu ] } - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -53,17 +48,11 @@ impl> AirScriptAir for PeriodicColu builder.when_first_row().assert_zero(main_current[0].clone().into()); // Main integrity/transition constraints - builder.assert_zero_ext(periodic_values[0].into() * (AB::ExprEF::from(main_current[1].clone().into()) + AB::ExprEF::from(main_current[2].clone().into()))); - builder.when_transition().assert_zero_ext(periodic_values[1].into() * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); + builder.assert_zero_ext(AB::ExprEF::from(periodic_values[0].clone().into()) * (AB::ExprEF::from(main_current[1].clone().into()) + AB::ExprEF::from(main_current[2].clone().into()))); + builder.when_transition().assert_zero_ext(AB::ExprEF::from(periodic_values[1].clone().into()) * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); // Aux boundary constraints // Aux integrity/transition constraints } -} - -impl Air for PeriodicColumnsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/periodic_columns/test_air_plonky3.rs b/air-script/src/tests/periodic_columns/test_air_plonky3.rs index fc3724624..42091fa46 100644 --- a/air-script/src/tests/periodic_columns/test_air_plonky3.rs +++ b/air-script/src/tests/periodic_columns/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs b/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs index e1643dd10..bbdef9bf9 100644 --- a/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs +++ b/air-script/src/tests/pub_inputs/pub_inputs_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct PubInputsAir; -impl BaseAir for PubInputsAir { +impl MidenAir for PubInputsAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for PubInputsAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for PubInputsAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -63,10 +47,4 @@ impl> AirScriptAir for PubInputsAir // Aux integrity/transition constraints } -} - -impl Air for PubInputsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/pub_inputs/test_air_plonky3.rs b/air-script/src/tests/pub_inputs/test_air_plonky3.rs index 742078244..8595358b4 100644 --- a/air-script/src/tests/pub_inputs/test_air_plonky3.rs +++ b/air-script/src/tests/pub_inputs/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs index ada569c95..7714372f2 100644 --- a/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_complex_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 6; pub const AUX_WIDTH: usize = 1; @@ -12,41 +13,75 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 2; pub struct SelectorsAir; -impl BaseAir for SelectorsAir { +impl MidenAir for SelectorsAir +where F: Field, + EF: ExtensionField, +{ fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for SelectorsAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES + fn num_randomness(&self) -> usize { + 1 + MAX_BETA_CHALLENGE_POWER } -} -impl> AirScriptAir for SelectorsAir { fn aux_width(&self) -> usize { AUX_WIDTH } - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } + fn build_aux_trace(&self, _main: &RowMajorMatrix, _challenges: &[EF]) -> Option> { + // Note: consider using Some(build_aux_trace_with_miden_vm::(_main, _challenges, module)) if you want to build the aux trace using Miden VM aux trace builders. - fn periodic_table(&self) -> Vec> { - vec![] + let num_rows = _main.height(); + let trace_length = num_rows * AUX_WIDTH; + let mut long_trace = EF::zero_vec(trace_length); + let mut trace = RowMajorMatrix::new(long_trace, AUX_WIDTH); + let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[EF; AUX_WIDTH]>() }; + assert!(prefix.is_empty(), "Alignment should match"); + assert!(suffix.is_empty(), "Alignment should match"); + assert_eq!(rows.len(), num_rows); + // Initialize first row + let initial_values = Self::buses_initial_values::(); + for j in 0..AUX_WIDTH { + rows[0][j] = initial_values[j]; + } + // Fill subsequent rows using direct access to the rows array + for i in 0..num_rows-1 { + let i_next = (i + 1) % num_rows; + let main_local = _main.row_slice(i).unwrap(); // i < height so unwrap should never fail. + let main_next = _main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail. + let main = VerticalPair::new( + RowMajorMatrixView::new_row(&*main_local), + RowMajorMatrixView::new_row(&*main_next), + ); + let periodic_values: [_; NUM_PERIODIC_VALUES] = >::periodic_table(self).iter().map(|col| col[i % col.len()]).collect::>().try_into().expect("Wrong number of periodic values"); + let prev_row = &rows[i]; + let next_row = Self::buses_transitions::( + &main, + _challenges, + &periodic_values, + prev_row, + ); + for j in 0..AUX_WIDTH { + rows[i+1][j] = next_row[j]; + } + } + Some(trace) } - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), main.row_slice(1).unwrap(), ); - let alpha = builder.alpha(); - let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect("Wrong number of beta challenges"); + let (&alpha, beta_challenges) = builder.permutation_randomness().split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect("Wrong number of aux bus boundary values"); let aux = builder.permutation(); let (aux_current, aux_next) = ( @@ -71,8 +106,29 @@ impl> AirScriptAir for SelectorsAir } } -impl Air for SelectorsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); +impl SelectorsAir { + fn buses_initial_values() -> Vec + where F: Field, + EF: ExtensionField, + { + vec![ + EF::ONE, + ] + } + + fn buses_transitions(main: &VerticalPair, RowMajorMatrixView>, challenges: &[EF], periodic_evals: &[F], aux_current: &[EF]) -> Vec + where F: Field, + EF: ExtensionField, + { + let (main_current, main_next) = ( + main.row_slice(0).unwrap(), + main.row_slice(1).unwrap(), + ); + let (&alpha, beta_challenges) = challenges.split_first().expect("Wrong number of randomness"); + let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect("Wrong number of randomness"); + let periodic_values: [_; NUM_PERIODIC_VALUES] = periodic_evals.try_into().expect("Wrong number of periodic values"); + vec![ + (((alpha + beta_challenges[0] + beta_challenges[1].double()) * EF::from(main_current[0].clone()) * EF::from(main_current[5].clone()) + EF::ONE - EF::from(main_current[0].clone()) * EF::from(main_current[5].clone())) * ((alpha + beta_challenges[0] + beta_challenges[1].double()) * (EF::ONE - EF::from(main_current[0].clone())) * EF::from(main_current[1].clone()) * EF::from(main_current[5].clone()) + EF::ONE - (EF::ONE - EF::from(main_current[0].clone())) * EF::from(main_current[1].clone()) * EF::from(main_current[5].clone())) * EF::from(aux_current[0].clone())) * ((alpha + EF::from_u64(3) * beta_challenges[0] + EF::from_u64(4) * beta_challenges[1]) * (EF::ONE - EF::from(main_current[0].clone())) * (EF::ONE - EF::from(main_current[1].clone())) * EF::from(main_current[4].clone()) + EF::ONE - (EF::ONE - EF::from(main_current[0].clone())) * (EF::ONE - EF::from(main_current[1].clone())) * EF::from(main_current[4].clone())).inverse(), + ] } } \ No newline at end of file diff --git a/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs index 74849eca0..df958a51e 100644 --- a/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_simple_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct SelectorsAir; -impl BaseAir for SelectorsAir { +impl MidenAir for SelectorsAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for SelectorsAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for SelectorsAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -57,10 +41,4 @@ impl> AirScriptAir for SelectorsAir // Aux integrity/transition constraints } -} - -impl Air for SelectorsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs b/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs index e86fa64d4..c7c4e3940 100644 --- a/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_combine_with_list_comprehensions_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 6; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct SelectorsAir; -impl BaseAir for SelectorsAir { +impl MidenAir for SelectorsAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for SelectorsAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for SelectorsAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -58,10 +42,4 @@ impl> AirScriptAir for SelectorsAir // Aux integrity/transition constraints } -} - -impl Air for SelectorsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/selectors/selectors_plonky3.rs b/air-script/src/tests/selectors/selectors_plonky3.rs index 1a00e1f17..51f70004b 100644 --- a/air-script/src/tests/selectors/selectors_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct SelectorsAir; -impl BaseAir for SelectorsAir { +impl MidenAir for SelectorsAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for SelectorsAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for SelectorsAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -57,10 +41,4 @@ impl> AirScriptAir for SelectorsAir // Aux integrity/transition constraints } -} - -impl Air for SelectorsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs b/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs index fa6bb3a35..1dde4fecf 100644 --- a/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs +++ b/air-script/src/tests/selectors/selectors_with_evaluators_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct SelectorsAir; -impl BaseAir for SelectorsAir { +impl MidenAir for SelectorsAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for SelectorsAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for SelectorsAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -57,10 +41,4 @@ impl> AirScriptAir for SelectorsAir // Aux integrity/transition constraints } -} - -impl Air for SelectorsAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/selectors/test_air_plonky3.rs b/air-script/src/tests/selectors/test_air_plonky3.rs index 3c5688ed1..ef3c01f81 100644 --- a/air-script/src/tests/selectors/test_air_plonky3.rs +++ b/air-script/src/tests/selectors/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/system/system_plonky3.rs b/air-script/src/tests/system/system_plonky3.rs index ee5fadc25..574bccd9b 100644 --- a/air-script/src/tests/system/system_plonky3.rs +++ b/air-script/src/tests/system/system_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 3; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct SystemAir; -impl BaseAir for SystemAir { +impl MidenAir for SystemAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for SystemAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for SystemAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -56,10 +40,4 @@ impl> AirScriptAir for SystemAir { // Aux integrity/transition constraints } -} - -impl Air for SystemAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/system/test_air_plonky3.rs b/air-script/src/tests/system/test_air_plonky3.rs index 969ce7f4e..404ea03d7 100644 --- a/air-script/src/tests/system/test_air_plonky3.rs +++ b/air-script/src/tests/system/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/trace_col_groups/test_air_plonky3.rs b/air-script/src/tests/trace_col_groups/test_air_plonky3.rs index 9c059df19..1b4522ecf 100644 --- a/air-script/src/tests/trace_col_groups/test_air_plonky3.rs +++ b/air-script/src/tests/trace_col_groups/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs b/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs index 39fb9ff02..026304e2d 100644 --- a/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs +++ b/air-script/src/tests/trace_col_groups/trace_col_groups_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 9; pub const AUX_WIDTH: usize = 0; @@ -12,34 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct TraceColGroupAir; -impl BaseAir for TraceColGroupAir { +impl MidenAir for TraceColGroupAir { fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for TraceColGroupAir { - fn num_public_values(&self) -> usize { - NUM_PUBLIC_VALUES - } -} - -impl> AirScriptAir for TraceColGroupAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } - - fn periodic_table(&self) -> Vec> { - vec![] - } - - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -57,10 +41,4 @@ impl> AirScriptAir for TraceColGrou // Aux integrity/transition constraints } -} - -impl Air for TraceColGroupAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air-script/src/tests/variables/test_air_plonky3.rs b/air-script/src/tests/variables/test_air_plonky3.rs index 3509c6925..b8d2d88ef 100644 --- a/air-script/src/tests/variables/test_air_plonky3.rs +++ b/air-script/src/tests/variables/test_air_plonky3.rs @@ -1,16 +1,5 @@ -use std::marker::PhantomData; - -use p3_challenger::{HashChallenger, SerializingChallenger64}; -use p3_circle::CirclePcs; -use p3_commit::ExtensionMmcs; -use p3_field::{PrimeCharacteristicRing, PrimeField64, extension::BinomialExtensionField}; -use p3_fri::create_benchmark_fri_params; -use p3_goldilocks::Goldilocks; -use p3_matrix::dense::RowMajorMatrix; -use p3_merkle_tree::MerkleTreeMmcs; -use p3_sha256::Sha256; -use p3_symmetric::{CompressionFunctionFromHasher, SerializingHasher}; -use p3_uni_stark::StarkConfig; +use p3_field::PrimeField64; +use p3_miden_air::RowMajorMatrix; use crate::{ generate_air_plonky3_test_with_airscript_traits, diff --git a/air-script/src/tests/variables/variables_plonky3.rs b/air-script/src/tests/variables/variables_plonky3.rs index d093f71de..bfe0da908 100644 --- a/air-script/src/tests/variables/variables_plonky3.rs +++ b/air-script/src/tests/variables/variables_plonky3.rs @@ -1,7 +1,8 @@ -use p3_air::{Air, BaseAir, BaseAirWithPublicValues, AirBuilder, ExtensionBuilder}; +use p3_field::{ExtensionField, Field, PrimeCharacteristicRing}; use p3_matrix::Matrix; -use p3_field::{Field, PrimeCharacteristicRing}; -use crate::test_utils::plonky3_traits::{AirScriptAir, AirScriptBuilder}; +use p3_matrix::dense::RowMajorMatrixView; +use p3_matrix::stack::VerticalPair; +use p3_miden_air::{MidenAir, MidenAirBuilder, RowMajorMatrix}; pub const MAIN_WIDTH: usize = 4; pub const AUX_WIDTH: usize = 0; @@ -12,26 +13,17 @@ pub const MAX_BETA_CHALLENGE_POWER: usize = 0; pub struct VariablesAir; -impl BaseAir for VariablesAir { +impl MidenAir for VariablesAir +where F: Field, + EF: ExtensionField, +{ fn width(&self) -> usize { MAIN_WIDTH } -} -impl BaseAirWithPublicValues for VariablesAir { fn num_public_values(&self) -> usize { NUM_PUBLIC_VALUES } -} - -impl> AirScriptAir for VariablesAir { - fn aux_width(&self) -> usize { - AUX_WIDTH - } - - fn max_beta_challenge_power(&self) -> usize { - MAX_BETA_CHALLENGE_POWER - } fn periodic_table(&self) -> Vec> { vec![ @@ -39,9 +31,12 @@ impl> AirScriptAir for VariablesAir ] } - fn eval(&self, builder: &mut AB) { + fn eval(&self, builder: &mut AB) + where AB: MidenAirBuilder, + { let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect("Wrong number of public values"); let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect("Wrong number of periodic values"); + let preprocessed = builder.preprocessed(); let main = builder.main(); let (main_current, main_next) = ( main.row_slice(0).unwrap(), @@ -54,7 +49,7 @@ impl> AirScriptAir for VariablesAir // Main integrity/transition constraints builder.assert_zero(main_current[0].clone().into() * main_current[0].clone().into() - main_current[0].clone().into()); - builder.when_transition().assert_zero_ext(periodic_values[0].into() * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); + builder.when_transition().assert_zero_ext(AB::ExprEF::from(periodic_values[0].clone().into()) * (AB::ExprEF::from(main_next[0].clone().into()) - AB::ExprEF::from(main_current[0].clone().into()))); builder.assert_zero((AB::Expr::ONE - main_current[0].clone().into()) * (main_current[3].clone().into() - main_current[1].clone().into() - main_current[2].clone().into()) - (AB::Expr::from_u64(6) - (AB::Expr::from_u64(7) - main_current[0].clone().into()))); builder.when_transition().assert_zero(main_current[0].clone().into() * (main_current[3].clone().into() - main_current[1].clone().into() * main_current[2].clone().into()) - (AB::Expr::ONE - main_next[0].clone().into())); @@ -62,10 +57,4 @@ impl> AirScriptAir for VariablesAir // Aux integrity/transition constraints } -} - -impl Air for VariablesAir { - fn eval(&self, builder: &mut AB) { - >::eval(self, builder); - } } \ No newline at end of file diff --git a/air/src/ir/mod.rs b/air/src/ir/mod.rs index 0393558ba..06758392c 100644 --- a/air/src/ir/mod.rs +++ b/air/src/ir/mod.rs @@ -162,7 +162,7 @@ use alloc::collections::BTreeMap; use miden_diagnostics::{SourceSpan, Spanned}; -use crate::graph::AlgebraicGraph; +use crate::{NodeIndex, graph::AlgebraicGraph}; /// The intermediate representation of a complete AirScript program /// @@ -195,6 +195,18 @@ pub struct Air { /// /// Only their name, type, and the first and last boundary constraints are stored here. pub buses: BTreeMap, + /// Buses initial values used for auxiliary trace generation (indexed by bus index) + pub buses_initial_values: BTreeMap, + /// Buses transition expressions used for auxiliary trace generation (indexed by bus index) + /// The tuple contains the numerator and an optional denominator operation (p_prime = numerator + /// if None or numerator / denominator), computed in the `ExpandBuses` Air pass depending on + /// the bus type + /// - for multiset buses: p' = p * columns_inserted_in_bus / columns_removed_from_bus + /// - for logup buses, if u corresponds to the columns inserted when s1 and v to the columns + /// removed when s2 + /// q' = q + s1 / u - s2 / v + /// = (q * u * v + s1 * v - s2 * u) / (u * v) + pub buses_transitions: BTreeMap)>, } impl Default for Air { fn default() -> Self { @@ -217,6 +229,8 @@ impl Air { num_random_values: 0, constraints: Default::default(), buses: Default::default(), + buses_initial_values: Default::default(), + buses_transitions: Default::default(), } } diff --git a/air/src/passes/common_subexpression_elimination.rs b/air/src/passes/common_subexpression_elimination.rs index bc162b0da..38711c81c 100644 --- a/air/src/passes/common_subexpression_elimination.rs +++ b/air/src/passes/common_subexpression_elimination.rs @@ -32,6 +32,28 @@ impl Pass for CommonSubexpressionElimination<'_> { // Update constraints with the new node indices ir.constraints.renumber_and_deduplicate_constraints(&renumbering_map); + // Iterate over all bus transition expression and renumber their node indices + for (_, value) in ir.buses_initial_values.iter_mut() { + let new_value_index = *renumbering_map + .get(value) + .expect("Error: cannot find value index in renumbering map"); + *value = new_value_index; + } + + // Iterate over all bus transition expression and renumber their node indices + for (_, (numerator, denominator)) in ir.buses_transitions.iter_mut() { + let new_numerator_index = *renumbering_map + .get(numerator) + .expect("Error: cannot find numerator index in renumbering map"); + *numerator = new_numerator_index; + if let Some(denominator) = denominator { + let new_denominator_index = *renumbering_map + .get(denominator) + .expect("Error: cannot find denominator index in renumbering map"); + *denominator = new_denominator_index; + } + } + Ok(ir) } } diff --git a/air/src/passes/expand_buses.rs b/air/src/passes/expand_buses.rs index 6c7780c3d..fb5a33513 100644 --- a/air/src/passes/expand_buses.rs +++ b/air/src/passes/expand_buses.rs @@ -63,6 +63,7 @@ impl Pass for BusOpExpand<'_> { bus_ops, bus_access, bus_access_with_offset, + bus_index, ); }, BusType::Logup => { @@ -71,6 +72,7 @@ impl Pass for BusOpExpand<'_> { bus_ops, bus_access, bus_access_with_offset, + bus_index, ); }, } @@ -139,6 +141,19 @@ impl<'a> BusOpExpand<'a> { }; // Store the generated constraint ir.constraints.insert_constraint(TraceSegmentId::Aux, root, domain); + + // Also store the initial value for auxiliary trace generation + if boundary == Boundary::First { + // TODO: May be invalid? For now, we put its value to zero + if let BusBoundary::PublicInputTable(_) = bus_boundary { + let value = ir + .constraint_graph_mut() + .insert_node(Operation::Value(crate::Value::Constant(0))); + ir.buses_initial_values.insert(bus_index, value); + } else { + ir.buses_initial_values.insert(bus_index, value); + } + } } /// Helper function to expand the integrity constraint of a multiset bus @@ -148,6 +163,7 @@ impl<'a> BusOpExpand<'a> { bus_ops: Vec, bus_access: NodeIndex, bus_access_with_offset: NodeIndex, + bus_index: usize, ) { let graph = ir.constraint_graph_mut(); @@ -239,6 +255,9 @@ impl<'a> BusOpExpand<'a> { root, ConstraintDomain::EveryFrame(2), ); + + // Also store the expression to computed p_prime for auxiliary trace generation + ir.buses_transitions.insert(bus_index, (p_prod, p_prime_factor)); } /// Helper function to expand the integrity constraint of a logup bus @@ -248,6 +267,7 @@ impl<'a> BusOpExpand<'a> { bus_ops: Vec, bus_access: NodeIndex, bus_access_with_offset: NodeIndex, + bus_index: usize, ) { let graph = ir.constraint_graph_mut(); // Example: @@ -375,10 +395,23 @@ impl<'a> BusOpExpand<'a> { // 5. Create the resulting constraint let root = graph.insert_node(Operation::Sub(q_term, q_prime_term)); + + // Also store the expression to computed q_prime for auxiliary trace generation + // Note: TODO: Potentially adapt CSE to handle this properly, otherwise indices might + // change... + let numerator = match terms_removed_from_bus { + Some(terms_removed_from_bus) => { + graph.insert_node(Operation::Sub(q_term, terms_removed_from_bus)) + }, + None => q_term, + }; + ir.constraints.insert_constraint( TraceSegmentId::Aux, root, ConstraintDomain::EveryFrame(2), ); + + ir.buses_transitions.insert(bus_index, (numerator, total_factors)); } } diff --git a/codegen/plonky3/src/air/graph.rs b/codegen/plonky3/src/air/graph.rs index 58a0309e7..f9c27ed7c 100644 --- a/codegen/plonky3/src/air/graph.rs +++ b/codegen/plonky3/src/air/graph.rs @@ -28,6 +28,7 @@ impl Codegen for TraceAccess { match elem_type { ElemType::Base => format!("{frame}_{row_offset}.clone().into()"), ElemType::Ext => format!("AB::ExprEF::from({frame}_{row_offset}.clone().into())"), + ElemType::ExtFieldElem => format!("EF::from({frame}_{row_offset}.clone())"), } } } @@ -54,16 +55,19 @@ impl Codegen for Value { fn to_string(&self, ir: &Air, elem_type: ElemType) -> String { match self { Value::Constant(0) => match elem_type { - ElemType::Base => "AB::Expr::ZERO".to_string(), - ElemType::Ext => "AB::ExprEF::ZERO".to_string(), + ElemType::Base => format!("AB::Expr::ZERO"), + ElemType::Ext => format!("AB::ExprEF::ZERO"), + ElemType::ExtFieldElem => format!("EF::ZERO"), }, Value::Constant(1) => match elem_type { - ElemType::Base => "AB::Expr::ONE".to_string(), - ElemType::Ext => "AB::ExprEF::ONE".to_string(), + ElemType::Base => format!("AB::Expr::ONE"), + ElemType::Ext => format!("AB::ExprEF::ONE"), + ElemType::ExtFieldElem => format!("EF::ONE"), }, Value::Constant(value) => match elem_type { ElemType::Base => format!("AB::Expr::from_u64({value})"), ElemType::Ext => format!("AB::ExprEF::from_u64({value})"), + ElemType::ExtFieldElem => format!("EF::from_u64({value})"), }, Value::TraceAccess(trace_access) => trace_access.to_string(ir, elem_type), Value::PublicInput(air_ir::PublicInputAccess { name, index }) => { @@ -78,7 +82,15 @@ impl Codegen for Value { Value::PeriodicColumn(pc) => { let index = ir.periodic_columns.iter().position(|(qid, _)| qid == &pc.name).unwrap(); - format!("periodic_values[{index}].into()") + match elem_type { + ElemType::Base => format!("AB::Expr::from(periodic_values[{index}].clone())"), + ElemType::Ext => { + format!("AB::ExprEF::from(periodic_values[{index}].clone().into())") + }, + ElemType::ExtFieldElem => { + format!("AB::EF::from(periodic_values[{index}].clone())") + }, + } }, Value::PublicInputTable(public_input_table_access) => { let idx = ir @@ -90,9 +102,17 @@ impl Codegen for Value { }, Value::RandomValue(idx) => { if *idx == 0 { - "alpha.into()".to_string() + if let ElemType::ExtFieldElem = elem_type { + format!("alpha") + } else { + format!("alpha.into()") + } } else { - format!("beta_challenges[{}].into()", idx - 1) + if let ElemType::ExtFieldElem = elem_type { + format!("beta_challenges[{}]", idx - 1) + } else { + format!("beta_challenges[{}].into()", idx - 1) + } } }, } diff --git a/codegen/plonky3/src/air/mod.rs b/codegen/plonky3/src/air/mod.rs index 13d87bc6f..98b881f70 100644 --- a/codegen/plonky3/src/air/mod.rs +++ b/codegen/plonky3/src/air/mod.rs @@ -7,6 +7,7 @@ use air_ir::Air; use super::Scope; use crate::air::{ boundary_constraints::{add_aux_boundary_constraints, add_main_boundary_constraints}, + graph::Codegen, integrity_constraints::{add_aux_integrity_constraints, add_main_integrity_constraints}, }; @@ -14,6 +15,7 @@ use crate::air::{ pub enum ElemType { Base, Ext, + ExtFieldElem, } // HELPERS TO GENERATE AN IMPLEMENTATION OF THE PLONKY3 AIR TRAIT @@ -28,13 +30,12 @@ pub(super) fn add_air(scope: &mut Scope, ir: &Air) { add_constants(scope, ir); // add the Air struct and its base implementation. - add_air_struct(scope, name); + add_air_struct(scope, ir, name); - // add AirScriptAir trait implementation for the provided AirIR. - add_air_script_trait(scope, ir, name); - - // add Plonky3 AirBuilder trait implementation for the provided AirIR. - add_air_trait(scope, name); + // add the aux trace generation utils if needed + if ir.num_random_values > 0 { + add_aux_trace_utils(scope, ir, name); + } } /// Updates the provided scope with constants needed for the custom Air struct and trait @@ -61,52 +62,35 @@ fn add_constants(scope: &mut Scope, ir: &Air) { } /// Updates the provided scope with a custom Air struct. -fn add_air_struct(scope: &mut Scope, name: &str) { +fn add_air_struct(scope: &mut Scope, ir: &Air, name: &str) { // define the custom Air struct. scope.new_struct(name).vis("pub"); - // add the custom BaseAir implementation block - let base_air_impl = scope.new_impl(name).generic("F").impl_trait("BaseAir"); - base_air_impl.new_fn("width").arg_ref_self().ret("usize").line("MAIN_WIDTH"); + // add the custom MidenAir implementation block + let miden_air_impl = + scope.new_impl(name).generic("F").generic("EF").impl_trait("MidenAir"); - // add the custom BaseAirWithPublicValues implementation block - let base_air_with_public_values_impl = - scope.new_impl(name).generic("F").impl_trait("BaseAirWithPublicValues"); - base_air_with_public_values_impl - .new_fn("num_public_values") - .arg_ref_self() - .ret("usize") - .line("NUM_PUBLIC_VALUES"); -} + if ir.num_random_values > 0 || ir.periodic_columns().count() > 0 { + miden_air_impl.bound("F", "Field").bound("EF", "ExtensionField"); + } -fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { - // add the custom AirScriptAir implementation block - let air_script_impl = scope - .new_impl(name) - .generic("F: Field") - .generic("AB: AirScriptBuilder") - .impl_trait("AirScriptAir"); - - // add the aux_width function - air_script_impl - .new_fn("aux_width") - .arg_ref_self() - .ret("usize") - .line("AUX_WIDTH"); + // add the width function + miden_air_impl.new_fn("width").arg_ref_self().ret("usize").line("MAIN_WIDTH"); - // add the max_beta_challenge_power function - air_script_impl - .new_fn("max_beta_challenge_power") - .arg_ref_self() - .ret("usize") - .line("MAX_BETA_CHALLENGE_POWER"); - - // add the periodic_table function - let periodic_table_func = - air_script_impl.new_fn("periodic_table").arg_ref_self().ret("Vec>"); - if ir.periodic_columns().count() == 0 { - periodic_table_func.line("vec![]"); - } else { + // add the num_public_values function if needed + if ir.periodic_columns().count() > 0 { + // add the custom BaseAirWithPublicValues implementation block + miden_air_impl + .new_fn("num_public_values") + .arg_ref_self() + .ret("usize") + .line("NUM_PUBLIC_VALUES"); + } + + // add the periodic_table function if needed + if ir.periodic_columns().count() > 0 { + let periodic_table_func = + miden_air_impl.new_fn("periodic_table").arg_ref_self().ret("Vec>"); periodic_table_func.line("vec!["); for col in ir.periodic_columns() { let values_str = col.values @@ -119,20 +103,85 @@ fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { periodic_table_func.line("]"); } + // add the num_randomness and aux_width functions if needed + if ir.num_random_values > 0 { + miden_air_impl + .new_fn("num_randomness") + .arg_ref_self() + .ret("usize") + .line("1 + MAX_BETA_CHALLENGE_POWER"); + + miden_air_impl.new_fn("aux_width").arg_ref_self().ret("usize").line("AUX_WIDTH"); + } + + // add the build_aux_trace function if needed + if ir.num_random_values > 0 { + let build_aux_trace_func = miden_air_impl + .new_fn("build_aux_trace") + .arg_ref_self() + .arg("_main", "&RowMajorMatrix") + .arg("_challenges", "&[EF]") + .ret("Option>"); + build_aux_trace_func.line("// Note: consider using Some(build_aux_trace_with_miden_vm::(_main, _challenges, module)) if you want to build the aux trace using Miden VM aux trace builders."); + build_aux_trace_func.line(""); + build_aux_trace_func.line("let num_rows = _main.height();"); + build_aux_trace_func.line("let trace_length = num_rows * AUX_WIDTH;"); + build_aux_trace_func.line("let mut long_trace = EF::zero_vec(trace_length);"); + build_aux_trace_func.line("let mut trace = RowMajorMatrix::new(long_trace, AUX_WIDTH);"); + build_aux_trace_func.line("let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<[EF; AUX_WIDTH]>() };"); + build_aux_trace_func.line("assert!(prefix.is_empty(), \"Alignment should match\");"); + build_aux_trace_func.line("assert!(suffix.is_empty(), \"Alignment should match\");"); + build_aux_trace_func.line("assert_eq!(rows.len(), num_rows);"); + build_aux_trace_func.line("// Initialize first row"); + build_aux_trace_func.line("let initial_values = Self::buses_initial_values::();"); + build_aux_trace_func.line("for j in 0..AUX_WIDTH {"); + build_aux_trace_func.line(" rows[0][j] = initial_values[j];"); + build_aux_trace_func.line("}"); + build_aux_trace_func.line("// Fill subsequent rows using direct access to the rows array"); + build_aux_trace_func.line("for i in 0..num_rows-1 {"); + build_aux_trace_func.line(" let i_next = (i + 1) % num_rows;"); + build_aux_trace_func.line(" let main_local = _main.row_slice(i).unwrap(); // i < height so unwrap should never fail."); + build_aux_trace_func.line(" let main_next = _main.row_slice(i_next).unwrap(); // i_next < height so unwrap should never fail."); + build_aux_trace_func.line(" let main = VerticalPair::new("); + build_aux_trace_func.line(" RowMajorMatrixView::new_row(&*main_local),"); + build_aux_trace_func.line(" RowMajorMatrixView::new_row(&*main_next),"); + build_aux_trace_func.line(" );"); + build_aux_trace_func.line(format!(" let periodic_values: [_; NUM_PERIODIC_VALUES] = <{name} as MidenAir>::periodic_table(self).iter().map(|col| col[i % col.len()]).collect::>().try_into().expect(\"Wrong number of periodic values\");")); + build_aux_trace_func.line(" let prev_row = &rows[i];"); + build_aux_trace_func.line(" let next_row = Self::buses_transitions::("); + build_aux_trace_func.line(" &main,"); + build_aux_trace_func.line(" _challenges,"); + build_aux_trace_func.line(" &periodic_values,"); + build_aux_trace_func.line(" prev_row,"); + build_aux_trace_func.line(" );"); + build_aux_trace_func.line(" for j in 0..AUX_WIDTH {"); + build_aux_trace_func.line(" rows[i+1][j] = next_row[j];"); + build_aux_trace_func.line(" }"); + build_aux_trace_func.line("}"); + build_aux_trace_func.line("Some(trace)"); + } + // add the eval function - let eval_func = air_script_impl.new_fn("eval").arg_ref_self().arg("builder", "&mut AB"); + let eval_func = miden_air_impl + .new_fn("eval") + .generic("AB") + .bound("AB", "MidenAirBuilder") + .arg_ref_self() + .arg("builder", "&mut AB"); eval_func.line("let public_values: [_; NUM_PUBLIC_VALUES] = builder.public_values().try_into().expect(\"Wrong number of public values\");"); eval_func.line("let periodic_values: [_; NUM_PERIODIC_VALUES] = builder.periodic_evals().try_into().expect(\"Wrong number of periodic values\");"); + eval_func.line("let preprocessed = builder.preprocessed();"); + eval_func.line("let main = builder.main();"); eval_func.line("let (main_current, main_next) = ("); eval_func.line(" main.row_slice(0).unwrap(),"); eval_func.line(" main.row_slice(1).unwrap(),"); eval_func.line(");"); - // Only had aux if there are random values + // Only add aux if there are random values if ir.num_random_values > 0 { - eval_func.line("let alpha = builder.alpha();"); - eval_func.line("let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = builder.beta_powers().try_into().expect(\"Wrong number of beta challenges\");"); + eval_func.line("let (&alpha, beta_challenges) = builder.permutation_randomness().split_first().expect(\"Wrong number of randomness\");"); + eval_func.line("let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect(\"Wrong number of randomness\");"); eval_func.line("let aux_bus_boundary_values: [_; AUX_WIDTH] = builder.aux_bus_boundary_values().try_into().expect(\"Wrong number of aux bus boundary values\");"); eval_func.line("let aux = builder.permutation();"); eval_func.line("let (aux_current, aux_next) = ("); @@ -150,12 +199,60 @@ fn add_air_script_trait(scope: &mut Scope, ir: &Air, name: &str) { add_aux_integrity_constraints(eval_func, ir); } -/// Updates the provided scope with the custom Air struct and an Air trait implementation based on -/// the provided AirIR. -fn add_air_trait(scope: &mut Scope, name: &str) { - // add the implementation block for the Air trait. - let air_impl = scope.new_impl(name).generic("AB: AirScriptBuilder").impl_trait("Air"); +/// Updates the provided scope with aux trace generation utilities. +fn add_aux_trace_utils(scope: &mut Scope, ir: &Air, name: &str) { + let aux_generation_impl = scope.new_impl(name); + + // add the bus_initial_values function + let buses_initial_values_func = aux_generation_impl + .new_fn("buses_initial_values") + .generic("F") + .generic("EF") + .bound("F", "Field") + .bound("EF", "ExtensionField") + .ret("Vec"); + buses_initial_values_func.line("vec!["); + for (_bus_id, value) in ir.buses_initial_values.iter() { + let value_str = value.to_string(ir, ElemType::ExtFieldElem); + + buses_initial_values_func.line(format!(" {},", value_str)); + } + buses_initial_values_func.line("]"); + + // add the bus_transitions function + let buses_transitions_func = aux_generation_impl + .new_fn("buses_transitions") + .generic("F") + .generic("EF") + .bound("F", "Field") + .bound("EF", "ExtensionField") + .arg("main", "&VerticalPair, RowMajorMatrixView>") + .arg("challenges", "&[EF]") + .arg("periodic_evals", "&[F]") + .arg("aux_current", "&[EF]") + .ret("Vec"); + + buses_transitions_func.line("let (main_current, main_next) = ("); + buses_transitions_func.line(" main.row_slice(0).unwrap(),"); + buses_transitions_func.line(" main.row_slice(1).unwrap(),"); + buses_transitions_func.line(");"); + buses_transitions_func.line("let (&alpha, beta_challenges) = challenges.split_first().expect(\"Wrong number of randomness\");"); + buses_transitions_func.line("let beta_challenges: [_; MAX_BETA_CHALLENGE_POWER] = beta_challenges.try_into().expect(\"Wrong number of randomness\");"); + + buses_transitions_func.line("let periodic_values: [_; NUM_PERIODIC_VALUES] = periodic_evals.try_into().expect(\"Wrong number of periodic values\");"); - let eval_func = air_impl.new_fn("eval").arg_ref_self().arg("builder", "&mut AB"); - eval_func.line(">::eval(self, builder);"); + buses_transitions_func.line("vec!["); + for (_bus_id, (numerator, denominator)) in ir.buses_transitions.iter() { + let numerator_str = numerator.to_string(ir, ElemType::ExtFieldElem); + + let aux_next_value_str = if let Some(denom) = denominator { + let denominator_str = denom.to_string(ir, ElemType::ExtFieldElem); + format!("({}) * ({}).inverse()", numerator_str, denominator_str) + } else { + numerator_str + }; + + buses_transitions_func.line(format!(" {},", aux_next_value_str)); + } + buses_transitions_func.line("]"); } diff --git a/codegen/plonky3/src/imports.rs b/codegen/plonky3/src/imports.rs index f26389b44..8655c7161 100644 --- a/codegen/plonky3/src/imports.rs +++ b/codegen/plonky3/src/imports.rs @@ -3,14 +3,13 @@ use super::Scope; /// Adds the required imports to the provided scope. pub(super) fn add_imports(scope: &mut Scope) { // add plonky3 imports - scope.import("p3_air", "Air"); - scope.import("p3_air", "BaseAir"); - scope.import("p3_air", "BaseAirWithPublicValues"); - scope.import("p3_air", "AirBuilder"); - scope.import("p3_air", "ExtensionBuilder"); - scope.import("p3_matrix", "Matrix"); + scope.import("p3_field", "ExtensionField"); scope.import("p3_field", "Field"); scope.import("p3_field", "PrimeCharacteristicRing"); - scope.import("crate::test_utils::plonky3_traits", "AirScriptAir"); - scope.import("crate::test_utils::plonky3_traits", "AirScriptBuilder"); + scope.import("p3_matrix", "Matrix"); + scope.import("p3_matrix::dense", "RowMajorMatrixView"); + scope.import("p3_matrix::stack", "VerticalPair"); + scope.import("p3_miden_air", "MidenAir"); + scope.import("p3_miden_air", "MidenAirBuilder"); + scope.import("p3_miden_air", "RowMajorMatrix"); }