diff --git a/.gitmodules b/.gitmodules index f643e34f4ca..9a73cfa279a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,7 @@ [submodule "barretenberg/sol/lib/openzeppelin-contracts"] path = barretenberg/sol/lib/openzeppelin-contracts url = https://github.com/OpenZeppelin/openzeppelin-contracts +[submodule "bb-pilcom/powdr"] + path = bb-pilcom/powdr + url = https://github.com/AztecProtocol/powdr + branch = avm-minimal diff --git a/barretenberg/cpp/pil/avm/kernel.pil b/barretenberg/cpp/pil/avm/kernel.pil index f7d402826eb..dff09f08d77 100644 --- a/barretenberg/cpp/pil/avm/kernel.pil +++ b/barretenberg/cpp/pil/avm/kernel.pil @@ -2,11 +2,11 @@ include "main.pil"; include "constants.pil"; namespace kernel(256); - pol public(/*idx=*/0) kernel_inputs; + pol public kernel_inputs; - pol public(/*idx=*/1) kernel_value_out; - pol public(/*idx=*/2) kernel_side_effect_out; - pol public(/*idx=*/3) kernel_metadata_out; + pol public kernel_value_out; + pol public kernel_side_effect_out; + pol public kernel_metadata_out; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6463): just use one col for both of these pol commit kernel_in_offset; diff --git a/barretenberg/cpp/scripts/compile_avm.sh b/barretenberg/cpp/scripts/compile_avm.sh index 01f422e229f..6ecc8817ab2 100755 --- a/barretenberg/cpp/scripts/compile_avm.sh +++ b/barretenberg/cpp/scripts/compile_avm.sh @@ -1,23 +1,4 @@ #!/bin/bash -use_zsh_alias() { - # Run Zsh command, source .zshrc, and then execute the alias - zsh -i -c "$1" -} # Compile -use_zsh_alias "bb_pil pil/avm/avm_main.pil --name Avm" - -# Format generated folders -root_dir="src" - -# Find all directories named 'generate' under the specified root directory -find "$root_dir" -type d -name 'generate' | while read dir_path; do - echo "Processing directory: $dir_path" - - # Find all C/C++ source files in these directories and format them - find "$dir_path" -type f \( -iname '*.hpp' -o -iname '*.cpp' \) -exec clang-format -i {} + -done - - -# Build vm tests -cmake --build --preset clang16 --target vm_tests \ No newline at end of file +../../bb-pilcom/target/release/bb_pil pil/avm/main.pil --name Avm diff --git a/barretenberg/cpp/scripts/rebuild_avm.sh b/barretenberg/cpp/scripts/rebuild_avm.sh new file mode 100755 index 00000000000..b6fa11dfc23 --- /dev/null +++ b/barretenberg/cpp/scripts/rebuild_avm.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Rebuild +./scripts/compile_avm.sh + +# Format generated folders +git add **/generated/* +./format.sh staged + +# Build vm tests +cmake --build --preset clang16 --target vm_tests \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/alu.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/alu.hpp index eda58900a6e..ff431393770 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/alu.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/alu.hpp @@ -326,7 +326,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(3); - auto tmp = (alu_cf * (-alu_cf + FF(1))); + auto tmp = ((alu_cf * (-alu_cf + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -334,7 +334,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(4); - auto tmp = (alu_ff_tag * (-alu_ff_tag + FF(1))); + auto tmp = ((alu_ff_tag * (-alu_ff_tag + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -342,7 +342,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(5); - auto tmp = (alu_u8_tag * (-alu_u8_tag + FF(1))); + auto tmp = ((alu_u8_tag * (-alu_u8_tag + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -350,7 +350,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(6); - auto tmp = (alu_u16_tag * (-alu_u16_tag + FF(1))); + auto tmp = ((alu_u16_tag * (-alu_u16_tag + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -358,7 +358,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(7); - auto tmp = (alu_u32_tag * (-alu_u32_tag + FF(1))); + auto tmp = ((alu_u32_tag * (-alu_u32_tag + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -366,7 +366,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(8); - auto tmp = (alu_u64_tag * (-alu_u64_tag + FF(1))); + auto tmp = ((alu_u64_tag * (-alu_u64_tag + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -374,7 +374,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(9); - auto tmp = (alu_u128_tag * (-alu_u128_tag + FF(1))); + auto tmp = ((alu_u128_tag * (-alu_u128_tag + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<9>(evals) += tmp; } @@ -382,9 +382,10 @@ template class aluImpl { { Avm_DECLARE_VIEWS(10); - auto tmp = - (alu_sel_alu * - ((((((alu_ff_tag + alu_u8_tag) + alu_u16_tag) + alu_u32_tag) + alu_u64_tag) + alu_u128_tag) - FF(1))); + auto tmp = ((alu_sel_alu * + ((((((alu_ff_tag + alu_u8_tag) + alu_u16_tag) + alu_u32_tag) + alu_u64_tag) + alu_u128_tag) - + FF(1))) - + FF(0)); tmp *= scaling_factor; std::get<10>(evals) += tmp; } @@ -403,17 +404,18 @@ template class aluImpl { { Avm_DECLARE_VIEWS(12); - auto tmp = - (((alu_op_add + alu_op_sub) * ((((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + - (alu_u16_r1 * FF(4294967296UL))) + - (alu_u16_r2 * FF(281474976710656UL))) + - (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + - (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + - (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) - - alu_ia) + - (alu_ff_tag * alu_ic))) + - ((alu_op_add - alu_op_sub) * ((alu_cf * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })) - alu_ib))); + auto tmp = ((((alu_op_add + alu_op_sub) * + ((((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + + (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + + (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) - + alu_ia) + + (alu_ff_tag * alu_ic))) + + ((alu_op_add - alu_op_sub) * ((alu_cf * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })) - alu_ib))) - + FF(0)); tmp *= scaling_factor; std::get<12>(evals) += tmp; } @@ -421,22 +423,23 @@ template class aluImpl { { Avm_DECLARE_VIEWS(13); - auto tmp = (((alu_op_add + alu_op_sub) * - (((((((alu_u8_tag * alu_u8_r0) + (alu_u16_tag * (alu_u8_r0 + (alu_u8_r1 * FF(256))))) + - (alu_u32_tag * ((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))))) + - (alu_u64_tag * ((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + - (alu_u16_r1 * FF(4294967296UL))) + - (alu_u16_r2 * FF(281474976710656UL))))) + - (alu_u128_tag * ((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + - (alu_u16_r1 * FF(4294967296UL))) + - (alu_u16_r2 * FF(281474976710656UL))) + - (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + - (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + - (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))))) + - (alu_ff_tag * alu_ia)) - - alu_ic)) + - ((alu_ff_tag * (alu_op_add - alu_op_sub)) * alu_ib)); + auto tmp = ((((alu_op_add + alu_op_sub) * + (((((((alu_u8_tag * alu_u8_r0) + (alu_u16_tag * (alu_u8_r0 + (alu_u8_r1 * FF(256))))) + + (alu_u32_tag * ((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))))) + + (alu_u64_tag * ((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))))) + + (alu_u128_tag * ((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + + (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + + (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))))) + + (alu_ff_tag * alu_ia)) - + alu_ic)) + + ((alu_ff_tag * (alu_op_add - alu_op_sub)) * alu_ib)) - + FF(0)); tmp *= scaling_factor; std::get<13>(evals) += tmp; } @@ -444,7 +447,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(14); - auto tmp = ((alu_ff_tag * alu_op_mul) * ((alu_ia * alu_ib) - alu_ic)); + auto tmp = (((alu_ff_tag * alu_op_mul) * ((alu_ia * alu_ib) - alu_ic)) - FF(0)); tmp *= scaling_factor; std::get<14>(evals) += tmp; } @@ -452,15 +455,16 @@ template class aluImpl { { Avm_DECLARE_VIEWS(15); - auto tmp = ((((-alu_ff_tag + FF(1)) - alu_u128_tag) * alu_op_mul) * - (((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + - (alu_u16_r1 * FF(4294967296UL))) + - (alu_u16_r2 * FF(281474976710656UL))) + - (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + - (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + - (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) - - (alu_ia * alu_ib))); + auto tmp = (((((-alu_ff_tag + FF(1)) - alu_u128_tag) * alu_op_mul) * + (((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + + (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + + (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))) - + (alu_ia * alu_ib))) - + FF(0)); tmp *= scaling_factor; std::get<15>(evals) += tmp; } @@ -469,12 +473,13 @@ template class aluImpl { Avm_DECLARE_VIEWS(16); auto tmp = - (alu_op_mul * (((((alu_u8_tag * alu_u8_r0) + (alu_u16_tag * (alu_u8_r0 + (alu_u8_r1 * FF(256))))) + - (alu_u32_tag * ((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))))) + - (alu_u64_tag * ((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + - (alu_u16_r1 * FF(4294967296UL))) + - (alu_u16_r2 * FF(281474976710656UL))))) - - (((-alu_ff_tag + FF(1)) - alu_u128_tag) * alu_ic))); + ((alu_op_mul * (((((alu_u8_tag * alu_u8_r0) + (alu_u16_tag * (alu_u8_r0 + (alu_u8_r1 * FF(256))))) + + (alu_u32_tag * ((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))))) + + (alu_u64_tag * ((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))))) - + (((-alu_ff_tag + FF(1)) - alu_u128_tag) * alu_ic))) - + FF(0)); tmp *= scaling_factor; std::get<16>(evals) += tmp; } @@ -482,14 +487,15 @@ template class aluImpl { { Avm_DECLARE_VIEWS(17); - auto tmp = ((alu_u128_tag * alu_op_mul) * - ((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + - (alu_u16_r1 * FF(4294967296UL))) + - (alu_u16_r2 * FF(281474976710656UL))) + - ((((alu_u16_r3 + (alu_u16_r4 * FF(65536))) + (alu_u16_r5 * FF(4294967296UL))) + - (alu_u16_r6 * FF(281474976710656UL))) * - FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - - alu_ia)); + auto tmp = (((alu_u128_tag * alu_op_mul) * + ((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + ((((alu_u16_r3 + (alu_u16_r4 * FF(65536))) + (alu_u16_r5 * FF(4294967296UL))) + + (alu_u16_r6 * FF(281474976710656UL))) * + FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - + alu_ia)) - + FF(0)); tmp *= scaling_factor; std::get<17>(evals) += tmp; } @@ -498,14 +504,15 @@ template class aluImpl { Avm_DECLARE_VIEWS(18); auto tmp = - ((alu_u128_tag * alu_op_mul) * - ((((((alu_u8_r0_shift + (alu_u8_r1_shift * FF(256))) + (alu_u16_r0_shift * FF(65536))) + - (alu_u16_r1_shift * FF(4294967296UL))) + - (alu_u16_r2_shift * FF(281474976710656UL))) + - ((((alu_u16_r3_shift + (alu_u16_r4_shift * FF(65536))) + (alu_u16_r5_shift * FF(4294967296UL))) + - (alu_u16_r6_shift * FF(281474976710656UL))) * - FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - - alu_ib)); + (((alu_u128_tag * alu_op_mul) * + ((((((alu_u8_r0_shift + (alu_u8_r1_shift * FF(256))) + (alu_u16_r0_shift * FF(65536))) + + (alu_u16_r1_shift * FF(4294967296UL))) + + (alu_u16_r2_shift * FF(281474976710656UL))) + + ((((alu_u16_r3_shift + (alu_u16_r4_shift * FF(65536))) + (alu_u16_r5_shift * FF(4294967296UL))) + + (alu_u16_r6_shift * FF(281474976710656UL))) * + FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - + alu_ib)) - + FF(0)); tmp *= scaling_factor; std::get<18>(evals) += tmp; } @@ -514,21 +521,22 @@ template class aluImpl { Avm_DECLARE_VIEWS(19); auto tmp = - ((alu_u128_tag * alu_op_mul) * - ((((alu_ia * ((((alu_u8_r0_shift + (alu_u8_r1_shift * FF(256))) + (alu_u16_r0_shift * FF(65536))) + - (alu_u16_r1_shift * FF(4294967296UL))) + - (alu_u16_r2_shift * FF(281474976710656UL)))) + - ((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + - (alu_u16_r1 * FF(4294967296UL))) + - (alu_u16_r2 * FF(281474976710656UL))) * - (((alu_u16_r3_shift + (alu_u16_r4_shift * FF(65536))) + (alu_u16_r5_shift * FF(4294967296UL))) + - (alu_u16_r6_shift * FF(281474976710656UL)))) * - FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - - (((alu_cf * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })) + - (((alu_u16_r7 + (alu_u16_r8 * FF(65536))) + (alu_u16_r9 * FF(4294967296UL))) + - (alu_u16_r10 * FF(281474976710656UL)))) * - FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - - alu_ic)); + (((alu_u128_tag * alu_op_mul) * + ((((alu_ia * ((((alu_u8_r0_shift + (alu_u8_r1_shift * FF(256))) + (alu_u16_r0_shift * FF(65536))) + + (alu_u16_r1_shift * FF(4294967296UL))) + + (alu_u16_r2_shift * FF(281474976710656UL)))) + + ((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) * + (((alu_u16_r3_shift + (alu_u16_r4_shift * FF(65536))) + (alu_u16_r5_shift * FF(4294967296UL))) + + (alu_u16_r6_shift * FF(281474976710656UL)))) * + FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) - + (((alu_cf * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })) + + (((alu_u16_r7 + (alu_u16_r8 * FF(65536))) + (alu_u16_r9 * FF(4294967296UL))) + + (alu_u16_r10 * FF(281474976710656UL)))) * + FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - + alu_ic)) - + FF(0)); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -536,7 +544,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(20); - auto tmp = (alu_op_not * alu_ff_tag); + auto tmp = ((alu_op_not * alu_ff_tag) - FF(0)); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -544,12 +552,12 @@ template class aluImpl { { Avm_DECLARE_VIEWS(21); - auto tmp = (alu_op_not * - ((alu_ia + alu_ic) - - ((((((alu_u8_tag * FF(256)) + (alu_u16_tag * FF(65536))) + (alu_u32_tag * FF(4294967296UL))) + - (alu_u64_tag * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (alu_u128_tag * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - - FF(1)))); + auto tmp = ((alu_op_not * ((alu_ia + alu_ic) - ((((((alu_u8_tag * FF(256)) + (alu_u16_tag * FF(65536))) + + (alu_u32_tag * FF(4294967296UL))) + + (alu_u64_tag * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u128_tag * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - + FF(1)))) - + FF(0)); tmp *= scaling_factor; std::get<21>(evals) += tmp; } @@ -557,7 +565,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(22); - auto tmp = ((alu_sel_cmp + alu_op_eq) * (alu_ic * (-alu_ic + FF(1)))); + auto tmp = (((alu_sel_cmp + alu_op_eq) * (alu_ic * (-alu_ic + FF(1)))) - FF(0)); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -566,9 +574,10 @@ template class aluImpl { Avm_DECLARE_VIEWS(23); auto tmp = - (alu_op_eq * - ((((alu_ia - alu_ib) * ((alu_ic * (-alu_op_eq_diff_inv + FF(1))) + alu_op_eq_diff_inv)) - FF(1)) + - alu_ic)); + ((alu_op_eq * + ((((alu_ia - alu_ib) * ((alu_ic * (-alu_op_eq_diff_inv + FF(1))) + alu_op_eq_diff_inv)) - FF(1)) + + alu_ic)) - + FF(0)); tmp *= scaling_factor; std::get<23>(evals) += tmp; } @@ -594,7 +603,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(26); - auto tmp = (alu_p_a_borrow * (-alu_p_a_borrow + FF(1))); + auto tmp = ((alu_p_a_borrow * (-alu_p_a_borrow + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<26>(evals) += tmp; } @@ -602,10 +611,11 @@ template class aluImpl { { Avm_DECLARE_VIEWS(27); - auto tmp = ((alu_p_sub_a_lo - - ((-alu_a_lo + FF(uint256_t{ 4891460686036598784UL, 2896914383306846353UL, 0UL, 0UL })) + - (alu_p_a_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })))) * - ((alu_sel_cmp + alu_op_cast) + alu_op_div_std)); + auto tmp = (((alu_p_sub_a_lo - + ((-alu_a_lo + FF(uint256_t{ 4891460686036598784UL, 2896914383306846353UL, 0UL, 0UL })) + + (alu_p_a_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })))) * + ((alu_sel_cmp + alu_op_cast) + alu_op_div_std)) - + FF(0)); tmp *= scaling_factor; std::get<27>(evals) += tmp; } @@ -613,10 +623,11 @@ template class aluImpl { { Avm_DECLARE_VIEWS(28); - auto tmp = ((alu_p_sub_a_hi - - ((-alu_a_hi + FF(uint256_t{ 13281191951274694749UL, 3486998266802970665UL, 0UL, 0UL })) - - alu_p_a_borrow)) * - ((alu_sel_cmp + alu_op_cast) + alu_op_div_std)); + auto tmp = (((alu_p_sub_a_hi - + ((-alu_a_hi + FF(uint256_t{ 13281191951274694749UL, 3486998266802970665UL, 0UL, 0UL })) - + alu_p_a_borrow)) * + ((alu_sel_cmp + alu_op_cast) + alu_op_div_std)) - + FF(0)); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -624,7 +635,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(29); - auto tmp = (alu_p_b_borrow * (-alu_p_b_borrow + FF(1))); + auto tmp = ((alu_p_b_borrow * (-alu_p_b_borrow + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -632,10 +643,11 @@ template class aluImpl { { Avm_DECLARE_VIEWS(30); - auto tmp = ((alu_p_sub_b_lo - - ((-alu_b_lo + FF(uint256_t{ 4891460686036598784UL, 2896914383306846353UL, 0UL, 0UL })) + - (alu_p_b_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })))) * - alu_sel_cmp); + auto tmp = (((alu_p_sub_b_lo - + ((-alu_b_lo + FF(uint256_t{ 4891460686036598784UL, 2896914383306846353UL, 0UL, 0UL })) + + (alu_p_b_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL })))) * + alu_sel_cmp) - + FF(0)); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -643,10 +655,11 @@ template class aluImpl { { Avm_DECLARE_VIEWS(31); - auto tmp = ((alu_p_sub_b_hi - - ((-alu_b_hi + FF(uint256_t{ 13281191951274694749UL, 3486998266802970665UL, 0UL, 0UL })) - - alu_p_b_borrow)) * - alu_sel_cmp); + auto tmp = (((alu_p_sub_b_hi - + ((-alu_b_hi + FF(uint256_t{ 13281191951274694749UL, 3486998266802970665UL, 0UL, 0UL })) - + alu_p_b_borrow)) * + alu_sel_cmp) - + FF(0)); tmp *= scaling_factor; std::get<31>(evals) += tmp; } @@ -654,12 +667,13 @@ template class aluImpl { { Avm_DECLARE_VIEWS(32); - auto tmp = ((alu_res_lo - - (((((alu_a_lo - alu_b_lo) - FF(1)) + (alu_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * - ((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte))) + - (((alu_b_lo - alu_a_lo) + (alu_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * - (-((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte)) + FF(1))))) * - alu_sel_cmp); + auto tmp = (((alu_res_lo - + (((((alu_a_lo - alu_b_lo) - FF(1)) + (alu_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * + ((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte))) + + (((alu_b_lo - alu_a_lo) + (alu_borrow * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) * + (-((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte)) + FF(1))))) * + alu_sel_cmp) - + FF(0)); tmp *= scaling_factor; std::get<32>(evals) += tmp; } @@ -668,11 +682,12 @@ template class aluImpl { Avm_DECLARE_VIEWS(33); auto tmp = - ((alu_res_hi - - ((((alu_a_hi - alu_b_hi) - alu_borrow) * ((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte))) + - (((alu_b_hi - alu_a_hi) - alu_borrow) * - (-((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte)) + FF(1))))) * - alu_sel_cmp); + (((alu_res_hi - + ((((alu_a_hi - alu_b_hi) - alu_borrow) * ((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte))) + + (((alu_b_hi - alu_a_hi) - alu_borrow) * + (-((alu_op_lt * alu_ic) + ((-alu_ic + FF(1)) * alu_op_lte)) + FF(1))))) * + alu_sel_cmp) - + FF(0)); tmp *= scaling_factor; std::get<33>(evals) += tmp; } @@ -680,7 +695,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(34); - auto tmp = (((alu_cmp_rng_ctr_shift - alu_cmp_rng_ctr) + FF(1)) * alu_cmp_rng_ctr); + auto tmp = ((((alu_cmp_rng_ctr_shift - alu_cmp_rng_ctr) + FF(1)) * alu_cmp_rng_ctr) - FF(0)); tmp *= scaling_factor; std::get<34>(evals) += tmp; } @@ -688,7 +703,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(35); - auto tmp = ((alu_cmp_rng_ctr_shift - FF(4)) * alu_sel_cmp); + auto tmp = (((alu_cmp_rng_ctr_shift - FF(4)) * alu_sel_cmp) - FF(0)); tmp *= scaling_factor; std::get<35>(evals) += tmp; } @@ -696,7 +711,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(36); - auto tmp = (alu_sel_rng_chk * (-alu_sel_rng_chk + FF(1))); + auto tmp = ((alu_sel_rng_chk * (-alu_sel_rng_chk + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<36>(evals) += tmp; } @@ -704,7 +719,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(37); - auto tmp = (alu_sel_rng_chk * alu_sel_cmp); + auto tmp = ((alu_sel_rng_chk * alu_sel_cmp) - FF(0)); tmp *= scaling_factor; std::get<37>(evals) += tmp; } @@ -712,9 +727,10 @@ template class aluImpl { { Avm_DECLARE_VIEWS(38); - auto tmp = ((alu_cmp_rng_ctr * - (((-alu_sel_rng_chk + FF(1)) * (-alu_op_eq_diff_inv + FF(1))) + alu_op_eq_diff_inv)) - - alu_sel_rng_chk); + auto tmp = (((alu_cmp_rng_ctr * + (((-alu_sel_rng_chk + FF(1)) * (-alu_op_eq_diff_inv + FF(1))) + alu_op_eq_diff_inv)) - + alu_sel_rng_chk) - + FF(0)); tmp *= scaling_factor; std::get<38>(evals) += tmp; } @@ -773,7 +789,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(42); - auto tmp = ((alu_a_lo_shift - alu_b_lo) * alu_sel_rng_chk_shift); + auto tmp = (((alu_a_lo_shift - alu_b_lo) * alu_sel_rng_chk_shift) - FF(0)); tmp *= scaling_factor; std::get<42>(evals) += tmp; } @@ -781,7 +797,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(43); - auto tmp = ((alu_a_hi_shift - alu_b_hi) * alu_sel_rng_chk_shift); + auto tmp = (((alu_a_hi_shift - alu_b_hi) * alu_sel_rng_chk_shift) - FF(0)); tmp *= scaling_factor; std::get<43>(evals) += tmp; } @@ -789,7 +805,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(44); - auto tmp = ((alu_b_lo_shift - alu_p_sub_a_lo) * alu_sel_rng_chk_shift); + auto tmp = (((alu_b_lo_shift - alu_p_sub_a_lo) * alu_sel_rng_chk_shift) - FF(0)); tmp *= scaling_factor; std::get<44>(evals) += tmp; } @@ -797,7 +813,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(45); - auto tmp = ((alu_b_hi_shift - alu_p_sub_a_hi) * alu_sel_rng_chk_shift); + auto tmp = (((alu_b_hi_shift - alu_p_sub_a_hi) * alu_sel_rng_chk_shift) - FF(0)); tmp *= scaling_factor; std::get<45>(evals) += tmp; } @@ -805,7 +821,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(46); - auto tmp = ((alu_p_sub_a_lo_shift - alu_p_sub_b_lo) * alu_sel_rng_chk_shift); + auto tmp = (((alu_p_sub_a_lo_shift - alu_p_sub_b_lo) * alu_sel_rng_chk_shift) - FF(0)); tmp *= scaling_factor; std::get<46>(evals) += tmp; } @@ -813,7 +829,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(47); - auto tmp = ((alu_p_sub_a_hi_shift - alu_p_sub_b_hi) * alu_sel_rng_chk_shift); + auto tmp = (((alu_p_sub_a_hi_shift - alu_p_sub_b_hi) * alu_sel_rng_chk_shift) - FF(0)); tmp *= scaling_factor; std::get<47>(evals) += tmp; } @@ -821,7 +837,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(48); - auto tmp = ((alu_p_sub_b_lo_shift - alu_res_lo) * alu_sel_rng_chk_shift); + auto tmp = (((alu_p_sub_b_lo_shift - alu_res_lo) * alu_sel_rng_chk_shift) - FF(0)); tmp *= scaling_factor; std::get<48>(evals) += tmp; } @@ -829,7 +845,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(49); - auto tmp = ((alu_p_sub_b_hi_shift - alu_res_hi) * alu_sel_rng_chk_shift); + auto tmp = (((alu_p_sub_b_hi_shift - alu_res_hi) * alu_sel_rng_chk_shift) - FF(0)); tmp *= scaling_factor; std::get<49>(evals) += tmp; } @@ -845,21 +861,22 @@ template class aluImpl { { Avm_DECLARE_VIEWS(51); - auto tmp = (alu_op_cast * - (((((((alu_u8_tag * alu_u8_r0) + (alu_u16_tag * (alu_u8_r0 + (alu_u8_r1 * FF(256))))) + - (alu_u32_tag * ((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))))) + - (alu_u64_tag * ((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + - (alu_u16_r1 * FF(4294967296UL))) + - (alu_u16_r2 * FF(281474976710656UL))))) + - (alu_u128_tag * ((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + - (alu_u16_r1 * FF(4294967296UL))) + - (alu_u16_r2 * FF(281474976710656UL))) + - (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + - (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + - (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))))) + - (alu_ff_tag * alu_ia)) - - alu_ic)); + auto tmp = ((alu_op_cast * + (((((((alu_u8_tag * alu_u8_r0) + (alu_u16_tag * (alu_u8_r0 + (alu_u8_r1 * FF(256))))) + + (alu_u32_tag * ((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))))) + + (alu_u64_tag * ((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))))) + + (alu_u128_tag * ((((((((alu_u8_r0 + (alu_u8_r1 * FF(256))) + (alu_u16_r0 * FF(65536))) + + (alu_u16_r1 * FF(4294967296UL))) + + (alu_u16_r2 * FF(281474976710656UL))) + + (alu_u16_r3 * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + (alu_u16_r4 * FF(uint256_t{ 0UL, 65536UL, 0UL, 0UL }))) + + (alu_u16_r5 * FF(uint256_t{ 0UL, 4294967296UL, 0UL, 0UL }))) + + (alu_u16_r6 * FF(uint256_t{ 0UL, 281474976710656UL, 0UL, 0UL }))))) + + (alu_ff_tag * alu_ia)) - + alu_ic)) - + FF(0)); tmp *= scaling_factor; std::get<51>(evals) += tmp; } @@ -867,7 +884,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(52); - auto tmp = (alu_op_cast * (alu_a_lo_shift - alu_p_sub_a_lo)); + auto tmp = ((alu_op_cast * (alu_a_lo_shift - alu_p_sub_a_lo)) - FF(0)); tmp *= scaling_factor; std::get<52>(evals) += tmp; } @@ -875,7 +892,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(53); - auto tmp = (alu_op_cast * (alu_a_hi_shift - alu_p_sub_a_hi)); + auto tmp = ((alu_op_cast * (alu_a_hi_shift - alu_p_sub_a_hi)) - FF(0)); tmp *= scaling_factor; std::get<53>(evals) += tmp; } @@ -883,7 +900,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(54); - auto tmp = (((alu_op_mul * alu_u128_tag) + alu_op_cast) * alu_sel_alu_shift); + auto tmp = ((((alu_op_mul * alu_u128_tag) + alu_op_cast) * alu_sel_alu_shift) - FF(0)); tmp *= scaling_factor; std::get<54>(evals) += tmp; } @@ -891,7 +908,8 @@ template class aluImpl { { Avm_DECLARE_VIEWS(55); - auto tmp = ((alu_shift_lt_bit_len * alu_op_shr) * (alu_a_lo - ((alu_two_pow_s - alu_b_lo) - FF(1)))); + auto tmp = + (((alu_shift_lt_bit_len * alu_op_shr) * (alu_a_lo - ((alu_two_pow_s - alu_b_lo) - FF(1)))) - FF(0)); tmp *= scaling_factor; std::get<55>(evals) += tmp; } @@ -899,7 +917,9 @@ template class aluImpl { { Avm_DECLARE_VIEWS(56); - auto tmp = ((alu_shift_lt_bit_len * alu_op_shr) * (alu_a_hi - ((alu_two_pow_t_sub_s - alu_b_hi) - FF(1)))); + auto tmp = + (((alu_shift_lt_bit_len * alu_op_shr) * (alu_a_hi - ((alu_two_pow_t_sub_s - alu_b_hi) - FF(1)))) - + FF(0)); tmp *= scaling_factor; std::get<56>(evals) += tmp; } @@ -907,7 +927,9 @@ template class aluImpl { { Avm_DECLARE_VIEWS(57); - auto tmp = ((alu_shift_lt_bit_len * alu_op_shl) * (alu_a_lo - ((alu_two_pow_t_sub_s - alu_b_lo) - FF(1)))); + auto tmp = + (((alu_shift_lt_bit_len * alu_op_shl) * (alu_a_lo - ((alu_two_pow_t_sub_s - alu_b_lo) - FF(1)))) - + FF(0)); tmp *= scaling_factor; std::get<57>(evals) += tmp; } @@ -915,7 +937,8 @@ template class aluImpl { { Avm_DECLARE_VIEWS(58); - auto tmp = ((alu_shift_lt_bit_len * alu_op_shl) * (alu_a_hi - ((alu_two_pow_s - alu_b_hi) - FF(1)))); + auto tmp = + (((alu_shift_lt_bit_len * alu_op_shl) * (alu_a_hi - ((alu_two_pow_s - alu_b_hi) - FF(1)))) - FF(0)); tmp *= scaling_factor; std::get<58>(evals) += tmp; } @@ -923,7 +946,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(59); - auto tmp = (alu_shift_lt_bit_len * (-alu_shift_lt_bit_len + FF(1))); + auto tmp = ((alu_shift_lt_bit_len * (-alu_shift_lt_bit_len + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<59>(evals) += tmp; } @@ -949,7 +972,8 @@ template class aluImpl { { Avm_DECLARE_VIEWS(61); - auto tmp = ((alu_shift_lt_bit_len * alu_op_shr) * (((alu_b_hi * alu_two_pow_s) + alu_b_lo) - alu_ia)); + auto tmp = + (((alu_shift_lt_bit_len * alu_op_shr) * (((alu_b_hi * alu_two_pow_s) + alu_b_lo) - alu_ia)) - FF(0)); tmp *= scaling_factor; std::get<61>(evals) += tmp; } @@ -957,7 +981,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(62); - auto tmp = (alu_op_shr * (alu_ic - (alu_b_hi * alu_shift_lt_bit_len))); + auto tmp = ((alu_op_shr * (alu_ic - (alu_b_hi * alu_shift_lt_bit_len))) - FF(0)); tmp *= scaling_factor; std::get<62>(evals) += tmp; } @@ -965,7 +989,9 @@ template class aluImpl { { Avm_DECLARE_VIEWS(63); - auto tmp = ((alu_shift_lt_bit_len * alu_op_shl) * (((alu_b_hi * alu_two_pow_t_sub_s) + alu_b_lo) - alu_ia)); + auto tmp = + (((alu_shift_lt_bit_len * alu_op_shl) * (((alu_b_hi * alu_two_pow_t_sub_s) + alu_b_lo) - alu_ia)) - + FF(0)); tmp *= scaling_factor; std::get<63>(evals) += tmp; } @@ -973,7 +999,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(64); - auto tmp = (alu_op_shl * (alu_ic - ((alu_b_lo * alu_two_pow_s) * alu_shift_lt_bit_len))); + auto tmp = ((alu_op_shl * (alu_ic - ((alu_b_lo * alu_two_pow_s) * alu_shift_lt_bit_len))) - FF(0)); tmp *= scaling_factor; std::get<64>(evals) += tmp; } @@ -989,7 +1015,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(66); - auto tmp = (alu_op_div_a_lt_b * (-alu_op_div_a_lt_b + FF(1))); + auto tmp = ((alu_op_div_a_lt_b * (-alu_op_div_a_lt_b + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<66>(evals) += tmp; } @@ -997,7 +1023,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(67); - auto tmp = (alu_op_div_a_lt_b * (alu_a_lo - ((alu_ib - alu_ia) - FF(1)))); + auto tmp = ((alu_op_div_a_lt_b * (alu_a_lo - ((alu_ib - alu_ia) - FF(1)))) - FF(0)); tmp *= scaling_factor; std::get<67>(evals) += tmp; } @@ -1005,7 +1031,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(68); - auto tmp = (alu_op_div_a_lt_b * alu_ic); + auto tmp = ((alu_op_div_a_lt_b * alu_ic) - FF(0)); tmp *= scaling_factor; std::get<68>(evals) += tmp; } @@ -1013,7 +1039,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(69); - auto tmp = (alu_op_div_a_lt_b * (alu_ia - alu_remainder)); + auto tmp = ((alu_op_div_a_lt_b * (alu_ia - alu_remainder)) - FF(0)); tmp *= scaling_factor; std::get<69>(evals) += tmp; } @@ -1021,7 +1047,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(70); - auto tmp = (alu_op_div_std * (-alu_op_div_std + FF(1))); + auto tmp = ((alu_op_div_std * (-alu_op_div_std + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<70>(evals) += tmp; } @@ -1029,8 +1055,9 @@ template class aluImpl { { Avm_DECLARE_VIEWS(71); - auto tmp = - (alu_op_div_std * ((alu_ib - alu_divisor_lo) - (alu_divisor_hi * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })))); + auto tmp = ((alu_op_div_std * + ((alu_ib - alu_divisor_lo) - (alu_divisor_hi * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })))) - + FF(0)); tmp *= scaling_factor; std::get<71>(evals) += tmp; } @@ -1038,8 +1065,9 @@ template class aluImpl { { Avm_DECLARE_VIEWS(72); - auto tmp = (alu_op_div_std * - ((alu_ic - alu_quotient_lo) - (alu_quotient_hi * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })))); + auto tmp = ((alu_op_div_std * + ((alu_ic - alu_quotient_lo) - (alu_quotient_hi * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL })))) - + FF(0)); tmp *= scaling_factor; std::get<72>(evals) += tmp; } @@ -1057,10 +1085,12 @@ template class aluImpl { Avm_DECLARE_VIEWS(74); auto tmp = - (alu_op_div_std * - ((((alu_divisor_lo * alu_quotient_lo) + (alu_partial_prod_lo * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - ((alu_partial_prod_hi + (alu_divisor_hi * alu_quotient_hi)) * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - - (alu_a_lo + (alu_a_hi * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))))); + ((alu_op_div_std * + ((((alu_divisor_lo * alu_quotient_lo) + (alu_partial_prod_lo * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + ((alu_partial_prod_hi + (alu_divisor_hi * alu_quotient_hi)) * + FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - + (alu_a_lo + (alu_a_hi * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))))) - + FF(0)); tmp *= scaling_factor; std::get<74>(evals) += tmp; } @@ -1068,7 +1098,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(75); - auto tmp = (alu_op_div_std * (alu_b_hi - ((alu_ib - alu_remainder) - FF(1)))); + auto tmp = ((alu_op_div_std * (alu_b_hi - ((alu_ib - alu_remainder) - FF(1)))) - FF(0)); tmp *= scaling_factor; std::get<75>(evals) += tmp; } @@ -1076,7 +1106,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(76); - auto tmp = ((alu_cmp_rng_ctr_shift - FF(2)) * alu_op_div_std); + auto tmp = (((alu_cmp_rng_ctr_shift - FF(2)) * alu_op_div_std) - FF(0)); tmp *= scaling_factor; std::get<76>(evals) += tmp; } @@ -1084,7 +1114,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(77); - auto tmp = (alu_sel_rng_chk * alu_op_div_std); + auto tmp = ((alu_sel_rng_chk * alu_op_div_std) - FF(0)); tmp *= scaling_factor; std::get<77>(evals) += tmp; } @@ -1093,10 +1123,12 @@ template class aluImpl { Avm_DECLARE_VIEWS(78); auto tmp = - (alu_op_div_std * - ((((alu_divisor_lo * alu_quotient_lo) + (alu_partial_prod_lo * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + - ((alu_partial_prod_hi + (alu_divisor_hi * alu_quotient_hi)) * FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - - (alu_ia - alu_remainder))); + ((alu_op_div_std * + ((((alu_divisor_lo * alu_quotient_lo) + (alu_partial_prod_lo * FF(uint256_t{ 0UL, 1UL, 0UL, 0UL }))) + + ((alu_partial_prod_hi + (alu_divisor_hi * alu_quotient_hi)) * + FF(uint256_t{ 0UL, 0UL, 1UL, 0UL }))) - + (alu_ia - alu_remainder))) - + FF(0)); tmp *= scaling_factor; std::get<78>(evals) += tmp; } @@ -1104,7 +1136,7 @@ template class aluImpl { { Avm_DECLARE_VIEWS(79); - auto tmp = (alu_sel_div_rng_chk * (-alu_sel_div_rng_chk + FF(1))); + auto tmp = ((alu_sel_div_rng_chk * (-alu_sel_div_rng_chk + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<79>(evals) += tmp; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/binary.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/binary.hpp index 98260f37337..615e12a21c9 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/binary.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/binary.hpp @@ -69,7 +69,7 @@ template class binaryImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (binary_sel_bin * (-binary_sel_bin + FF(1))); + auto tmp = ((binary_sel_bin * (-binary_sel_bin + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<0>(evals) += tmp; } @@ -77,7 +77,7 @@ template class binaryImpl { { Avm_DECLARE_VIEWS(1); - auto tmp = ((binary_op_id_shift - binary_op_id) * binary_mem_tag_ctr); + auto tmp = (((binary_op_id_shift - binary_op_id) * binary_mem_tag_ctr) - FF(0)); tmp *= scaling_factor; std::get<1>(evals) += tmp; } @@ -85,7 +85,7 @@ template class binaryImpl { { Avm_DECLARE_VIEWS(2); - auto tmp = (((binary_mem_tag_ctr_shift - binary_mem_tag_ctr) + FF(1)) * binary_mem_tag_ctr); + auto tmp = ((((binary_mem_tag_ctr_shift - binary_mem_tag_ctr) + FF(1)) * binary_mem_tag_ctr) - FF(0)); tmp *= scaling_factor; std::get<2>(evals) += tmp; } @@ -93,9 +93,10 @@ template class binaryImpl { { Avm_DECLARE_VIEWS(3); - auto tmp = ((binary_mem_tag_ctr * - (((-binary_sel_bin + FF(1)) * (-binary_mem_tag_ctr_inv + FF(1))) + binary_mem_tag_ctr_inv)) - - binary_sel_bin); + auto tmp = (((binary_mem_tag_ctr * + (((-binary_sel_bin + FF(1)) * (-binary_mem_tag_ctr_inv + FF(1))) + binary_mem_tag_ctr_inv)) - + binary_sel_bin) - + FF(0)); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -103,7 +104,7 @@ template class binaryImpl { { Avm_DECLARE_VIEWS(4); - auto tmp = ((-binary_sel_bin + FF(1)) * binary_acc_ia); + auto tmp = (((-binary_sel_bin + FF(1)) * binary_acc_ia) - FF(0)); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -111,7 +112,7 @@ template class binaryImpl { { Avm_DECLARE_VIEWS(5); - auto tmp = ((-binary_sel_bin + FF(1)) * binary_acc_ib); + auto tmp = (((-binary_sel_bin + FF(1)) * binary_acc_ib) - FF(0)); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -119,7 +120,7 @@ template class binaryImpl { { Avm_DECLARE_VIEWS(6); - auto tmp = ((-binary_sel_bin + FF(1)) * binary_acc_ic); + auto tmp = (((-binary_sel_bin + FF(1)) * binary_acc_ic) - FF(0)); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -127,7 +128,8 @@ template class binaryImpl { { Avm_DECLARE_VIEWS(7); - auto tmp = (((binary_acc_ia - binary_ia_bytes) - (binary_acc_ia_shift * FF(256))) * binary_mem_tag_ctr); + auto tmp = + ((((binary_acc_ia - binary_ia_bytes) - (binary_acc_ia_shift * FF(256))) * binary_mem_tag_ctr) - FF(0)); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -135,7 +137,8 @@ template class binaryImpl { { Avm_DECLARE_VIEWS(8); - auto tmp = (((binary_acc_ib - binary_ib_bytes) - (binary_acc_ib_shift * FF(256))) * binary_mem_tag_ctr); + auto tmp = + ((((binary_acc_ib - binary_ib_bytes) - (binary_acc_ib_shift * FF(256))) * binary_mem_tag_ctr) - FF(0)); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -143,7 +146,8 @@ template class binaryImpl { { Avm_DECLARE_VIEWS(9); - auto tmp = (((binary_acc_ic - binary_ic_bytes) - (binary_acc_ic_shift * FF(256))) * binary_mem_tag_ctr); + auto tmp = + ((((binary_acc_ic - binary_ic_bytes) - (binary_acc_ic_shift * FF(256))) * binary_mem_tag_ctr) - FF(0)); tmp *= scaling_factor; std::get<9>(evals) += tmp; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/conversion.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/conversion.hpp index b83fb6bf7ac..a51605c8f18 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/conversion.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/conversion.hpp @@ -37,7 +37,7 @@ template class conversionImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (conversion_sel_to_radix_le * (-conversion_sel_to_radix_le + FF(1))); + auto tmp = ((conversion_sel_to_radix_le * (-conversion_sel_to_radix_le + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<0>(evals) += tmp; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp index ef1db050b75..9dd3eb86948 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/declare_views.hpp @@ -4,6 +4,10 @@ using View = typename Accumulator::View; \ [[maybe_unused]] auto main_clk = View(new_term.main_clk); \ [[maybe_unused]] auto main_sel_first = View(new_term.main_sel_first); \ + [[maybe_unused]] auto kernel_kernel_inputs = View(new_term.kernel_kernel_inputs); \ + [[maybe_unused]] auto kernel_kernel_value_out = View(new_term.kernel_kernel_value_out); \ + [[maybe_unused]] auto kernel_kernel_side_effect_out = View(new_term.kernel_kernel_side_effect_out); \ + [[maybe_unused]] auto kernel_kernel_metadata_out = View(new_term.kernel_kernel_metadata_out); \ [[maybe_unused]] auto alu_a_hi = View(new_term.alu_a_hi); \ [[maybe_unused]] auto alu_a_lo = View(new_term.alu_a_lo); \ [[maybe_unused]] auto alu_b_hi = View(new_term.alu_b_hi); \ @@ -126,11 +130,7 @@ [[maybe_unused]] auto kernel_emit_unencrypted_log_write_offset = \ View(new_term.kernel_emit_unencrypted_log_write_offset); \ [[maybe_unused]] auto kernel_kernel_in_offset = View(new_term.kernel_kernel_in_offset); \ - [[maybe_unused]] auto kernel_kernel_inputs = View(new_term.kernel_kernel_inputs); \ - [[maybe_unused]] auto kernel_kernel_metadata_out = View(new_term.kernel_kernel_metadata_out); \ [[maybe_unused]] auto kernel_kernel_out_offset = View(new_term.kernel_kernel_out_offset); \ - [[maybe_unused]] auto kernel_kernel_side_effect_out = View(new_term.kernel_kernel_side_effect_out); \ - [[maybe_unused]] auto kernel_kernel_value_out = View(new_term.kernel_kernel_value_out); \ [[maybe_unused]] auto kernel_l1_to_l2_msg_exists_write_offset = \ View(new_term.kernel_l1_to_l2_msg_exists_write_offset); \ [[maybe_unused]] auto kernel_note_hash_exist_write_offset = View(new_term.kernel_note_hash_exist_write_offset); \ diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/keccakf1600.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/keccakf1600.hpp index 56e0a9e6a5d..18989c0e836 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/keccakf1600.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/keccakf1600.hpp @@ -37,7 +37,7 @@ template class keccakf1600Impl { { Avm_DECLARE_VIEWS(0); - auto tmp = (keccakf1600_sel_keccakf1600 * (-keccakf1600_sel_keccakf1600 + FF(1))); + auto tmp = ((keccakf1600_sel_keccakf1600 * (-keccakf1600_sel_keccakf1600 + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<0>(evals) += tmp; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel.hpp index a53770f6481..e9e0d0e1748 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/kernel.hpp @@ -98,8 +98,9 @@ template class kernelImpl { Avm_DECLARE_VIEWS(0); auto tmp = - ((-main_sel_last + FF(1)) * (kernel_note_hash_exist_write_offset_shift - - (kernel_note_hash_exist_write_offset + main_sel_op_note_hash_exists))); + (((-main_sel_last + FF(1)) * (kernel_note_hash_exist_write_offset_shift - + (kernel_note_hash_exist_write_offset + main_sel_op_note_hash_exists))) - + FF(0)); tmp *= scaling_factor; std::get<0>(evals) += tmp; } @@ -107,8 +108,10 @@ template class kernelImpl { { Avm_DECLARE_VIEWS(1); - auto tmp = ((-main_sel_last + FF(1)) * (kernel_emit_note_hash_write_offset_shift - - (kernel_emit_note_hash_write_offset + main_sel_op_emit_note_hash))); + auto tmp = + (((-main_sel_last + FF(1)) * (kernel_emit_note_hash_write_offset_shift - + (kernel_emit_note_hash_write_offset + main_sel_op_emit_note_hash))) - + FF(0)); tmp *= scaling_factor; std::get<1>(evals) += tmp; } @@ -116,9 +119,10 @@ template class kernelImpl { { Avm_DECLARE_VIEWS(2); - auto tmp = ((-main_sel_last + FF(1)) * - (kernel_nullifier_exists_write_offset_shift - - (kernel_nullifier_exists_write_offset + (main_sel_op_nullifier_exists * main_ib)))); + auto tmp = (((-main_sel_last + FF(1)) * + (kernel_nullifier_exists_write_offset_shift - + (kernel_nullifier_exists_write_offset + (main_sel_op_nullifier_exists * main_ib)))) - + FF(0)); tmp *= scaling_factor; std::get<2>(evals) += tmp; } @@ -127,9 +131,10 @@ template class kernelImpl { Avm_DECLARE_VIEWS(3); auto tmp = - ((-main_sel_last + FF(1)) * - (kernel_nullifier_non_exists_write_offset_shift - - (kernel_nullifier_non_exists_write_offset + (main_sel_op_nullifier_exists * (-main_ib + FF(1)))))); + (((-main_sel_last + FF(1)) * + (kernel_nullifier_non_exists_write_offset_shift - + (kernel_nullifier_non_exists_write_offset + (main_sel_op_nullifier_exists * (-main_ib + FF(1)))))) - + FF(0)); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -137,8 +142,10 @@ template class kernelImpl { { Avm_DECLARE_VIEWS(4); - auto tmp = ((-main_sel_last + FF(1)) * (kernel_emit_nullifier_write_offset_shift - - (kernel_emit_nullifier_write_offset + main_sel_op_emit_nullifier))); + auto tmp = + (((-main_sel_last + FF(1)) * (kernel_emit_nullifier_write_offset_shift - + (kernel_emit_nullifier_write_offset + main_sel_op_emit_nullifier))) - + FF(0)); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -146,9 +153,10 @@ template class kernelImpl { { Avm_DECLARE_VIEWS(5); - auto tmp = ((-main_sel_last + FF(1)) * - (kernel_l1_to_l2_msg_exists_write_offset_shift - - (kernel_l1_to_l2_msg_exists_write_offset + main_sel_op_l1_to_l2_msg_exists))); + auto tmp = (((-main_sel_last + FF(1)) * + (kernel_l1_to_l2_msg_exists_write_offset_shift - + (kernel_l1_to_l2_msg_exists_write_offset + main_sel_op_l1_to_l2_msg_exists))) - + FF(0)); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -156,9 +164,10 @@ template class kernelImpl { { Avm_DECLARE_VIEWS(6); - auto tmp = ((-main_sel_last + FF(1)) * - (kernel_emit_unencrypted_log_write_offset_shift - - (kernel_emit_unencrypted_log_write_offset + main_sel_op_emit_unencrypted_log))); + auto tmp = (((-main_sel_last + FF(1)) * + (kernel_emit_unencrypted_log_write_offset_shift - + (kernel_emit_unencrypted_log_write_offset + main_sel_op_emit_unencrypted_log))) - + FF(0)); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -166,9 +175,10 @@ template class kernelImpl { { Avm_DECLARE_VIEWS(7); - auto tmp = - ((-main_sel_last + FF(1)) * (kernel_emit_l2_to_l1_msg_write_offset_shift - - (kernel_emit_l2_to_l1_msg_write_offset + main_sel_op_emit_l2_to_l1_msg))); + auto tmp = (((-main_sel_last + FF(1)) * + (kernel_emit_l2_to_l1_msg_write_offset_shift - + (kernel_emit_l2_to_l1_msg_write_offset + main_sel_op_emit_l2_to_l1_msg))) - + FF(0)); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -176,8 +186,9 @@ template class kernelImpl { { Avm_DECLARE_VIEWS(8); - auto tmp = ((-main_sel_last + FF(1)) * - (kernel_sload_write_offset_shift - (kernel_sload_write_offset + main_sel_op_sload))); + auto tmp = (((-main_sel_last + FF(1)) * + (kernel_sload_write_offset_shift - (kernel_sload_write_offset + main_sel_op_sload))) - + FF(0)); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -185,8 +196,9 @@ template class kernelImpl { { Avm_DECLARE_VIEWS(9); - auto tmp = ((-main_sel_last + FF(1)) * - (kernel_sstore_write_offset_shift - (kernel_sstore_write_offset + main_sel_op_sstore))); + auto tmp = (((-main_sel_last + FF(1)) * + (kernel_sstore_write_offset_shift - (kernel_sstore_write_offset + main_sel_op_sstore))) - + FF(0)); tmp *= scaling_factor; std::get<9>(evals) += tmp; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp index 38835bdab22..1517e106ca7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/main.hpp @@ -307,7 +307,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (main_l2_out_of_gas * (-main_l2_out_of_gas + FF(1))); + auto tmp = ((main_l2_out_of_gas * (-main_l2_out_of_gas + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<0>(evals) += tmp; } @@ -315,7 +315,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(1); - auto tmp = (main_da_out_of_gas * (-main_da_out_of_gas + FF(1))); + auto tmp = ((main_da_out_of_gas * (-main_da_out_of_gas + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<1>(evals) += tmp; } @@ -323,8 +323,9 @@ template class mainImpl { { Avm_DECLARE_VIEWS(2); - auto tmp = (main_sel_gas_accounting_active * - ((main_l2_gas_remaining_shift - main_l2_gas_remaining) + main_l2_gas_op_cost)); + auto tmp = ((main_sel_gas_accounting_active * + ((main_l2_gas_remaining_shift - main_l2_gas_remaining) + main_l2_gas_op_cost)) - + FF(0)); tmp *= scaling_factor; std::get<2>(evals) += tmp; } @@ -332,8 +333,9 @@ template class mainImpl { { Avm_DECLARE_VIEWS(3); - auto tmp = (main_sel_gas_accounting_active * - ((main_da_gas_remaining_shift - main_da_gas_remaining) + main_da_gas_op_cost)); + auto tmp = ((main_sel_gas_accounting_active * + ((main_da_gas_remaining_shift - main_da_gas_remaining) + main_da_gas_op_cost)) - + FF(0)); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -341,7 +343,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(4); - auto tmp = ((-main_sel_gas_accounting_active + FF(1)) * main_l2_gas_op_cost); + auto tmp = (((-main_sel_gas_accounting_active + FF(1)) * main_l2_gas_op_cost) - FF(0)); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -349,7 +351,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(5); - auto tmp = ((-main_sel_gas_accounting_active + FF(1)) * main_da_gas_op_cost); + auto tmp = (((-main_sel_gas_accounting_active + FF(1)) * main_da_gas_op_cost) - FF(0)); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -357,10 +359,11 @@ template class mainImpl { { Avm_DECLARE_VIEWS(6); - auto tmp = (main_sel_gas_accounting_active * - ((((-(main_l2_out_of_gas * FF(2)) + FF(1)) * main_l2_gas_remaining_shift) - - (main_abs_l2_rem_gas_hi * FF(65536))) - - main_abs_l2_rem_gas_lo)); + auto tmp = ((main_sel_gas_accounting_active * + ((((-(main_l2_out_of_gas * FF(2)) + FF(1)) * main_l2_gas_remaining_shift) - + (main_abs_l2_rem_gas_hi * FF(65536))) - + main_abs_l2_rem_gas_lo)) - + FF(0)); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -368,10 +371,11 @@ template class mainImpl { { Avm_DECLARE_VIEWS(7); - auto tmp = (main_sel_gas_accounting_active * - ((((-(main_da_out_of_gas * FF(2)) + FF(1)) * main_da_gas_remaining_shift) - - (main_abs_da_rem_gas_hi * FF(65536))) - - main_abs_da_rem_gas_lo)); + auto tmp = ((main_sel_gas_accounting_active * + ((((-(main_da_out_of_gas * FF(2)) + FF(1)) * main_da_gas_remaining_shift) - + (main_abs_da_rem_gas_hi * FF(65536))) - + main_abs_da_rem_gas_lo)) - + FF(0)); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -379,7 +383,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(8); - auto tmp = (main_sel_op_sender * (-main_sel_op_sender + FF(1))); + auto tmp = ((main_sel_op_sender * (-main_sel_op_sender + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -387,7 +391,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(9); - auto tmp = (main_sel_op_address * (-main_sel_op_address + FF(1))); + auto tmp = ((main_sel_op_address * (-main_sel_op_address + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<9>(evals) += tmp; } @@ -395,7 +399,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(10); - auto tmp = (main_sel_op_storage_address * (-main_sel_op_storage_address + FF(1))); + auto tmp = ((main_sel_op_storage_address * (-main_sel_op_storage_address + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<10>(evals) += tmp; } @@ -403,7 +407,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(11); - auto tmp = (main_sel_op_chain_id * (-main_sel_op_chain_id + FF(1))); + auto tmp = ((main_sel_op_chain_id * (-main_sel_op_chain_id + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<11>(evals) += tmp; } @@ -411,7 +415,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(12); - auto tmp = (main_sel_op_version * (-main_sel_op_version + FF(1))); + auto tmp = ((main_sel_op_version * (-main_sel_op_version + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<12>(evals) += tmp; } @@ -419,7 +423,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(13); - auto tmp = (main_sel_op_block_number * (-main_sel_op_block_number + FF(1))); + auto tmp = ((main_sel_op_block_number * (-main_sel_op_block_number + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<13>(evals) += tmp; } @@ -427,7 +431,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(14); - auto tmp = (main_sel_op_coinbase * (-main_sel_op_coinbase + FF(1))); + auto tmp = ((main_sel_op_coinbase * (-main_sel_op_coinbase + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<14>(evals) += tmp; } @@ -435,7 +439,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(15); - auto tmp = (main_sel_op_timestamp * (-main_sel_op_timestamp + FF(1))); + auto tmp = ((main_sel_op_timestamp * (-main_sel_op_timestamp + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<15>(evals) += tmp; } @@ -443,7 +447,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(16); - auto tmp = (main_sel_op_fee_per_l2_gas * (-main_sel_op_fee_per_l2_gas + FF(1))); + auto tmp = ((main_sel_op_fee_per_l2_gas * (-main_sel_op_fee_per_l2_gas + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<16>(evals) += tmp; } @@ -451,7 +455,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(17); - auto tmp = (main_sel_op_fee_per_da_gas * (-main_sel_op_fee_per_da_gas + FF(1))); + auto tmp = ((main_sel_op_fee_per_da_gas * (-main_sel_op_fee_per_da_gas + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<17>(evals) += tmp; } @@ -459,7 +463,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(18); - auto tmp = (main_sel_op_transaction_fee * (-main_sel_op_transaction_fee + FF(1))); + auto tmp = ((main_sel_op_transaction_fee * (-main_sel_op_transaction_fee + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<18>(evals) += tmp; } @@ -467,7 +471,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(19); - auto tmp = (main_sel_op_l2gasleft * (-main_sel_op_l2gasleft + FF(1))); + auto tmp = ((main_sel_op_l2gasleft * (-main_sel_op_l2gasleft + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<19>(evals) += tmp; } @@ -475,7 +479,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(20); - auto tmp = (main_sel_op_dagasleft * (-main_sel_op_dagasleft + FF(1))); + auto tmp = ((main_sel_op_dagasleft * (-main_sel_op_dagasleft + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -483,7 +487,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(21); - auto tmp = (main_sel_op_note_hash_exists * (-main_sel_op_note_hash_exists + FF(1))); + auto tmp = ((main_sel_op_note_hash_exists * (-main_sel_op_note_hash_exists + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<21>(evals) += tmp; } @@ -491,7 +495,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(22); - auto tmp = (main_sel_op_emit_note_hash * (-main_sel_op_emit_note_hash + FF(1))); + auto tmp = ((main_sel_op_emit_note_hash * (-main_sel_op_emit_note_hash + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -499,7 +503,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(23); - auto tmp = (main_sel_op_nullifier_exists * (-main_sel_op_nullifier_exists + FF(1))); + auto tmp = ((main_sel_op_nullifier_exists * (-main_sel_op_nullifier_exists + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<23>(evals) += tmp; } @@ -507,7 +511,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(24); - auto tmp = (main_sel_op_emit_nullifier * (-main_sel_op_emit_nullifier + FF(1))); + auto tmp = ((main_sel_op_emit_nullifier * (-main_sel_op_emit_nullifier + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<24>(evals) += tmp; } @@ -515,7 +519,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(25); - auto tmp = (main_sel_op_l1_to_l2_msg_exists * (-main_sel_op_l1_to_l2_msg_exists + FF(1))); + auto tmp = ((main_sel_op_l1_to_l2_msg_exists * (-main_sel_op_l1_to_l2_msg_exists + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<25>(evals) += tmp; } @@ -523,7 +527,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(26); - auto tmp = (main_sel_op_emit_unencrypted_log * (-main_sel_op_emit_unencrypted_log + FF(1))); + auto tmp = ((main_sel_op_emit_unencrypted_log * (-main_sel_op_emit_unencrypted_log + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<26>(evals) += tmp; } @@ -531,7 +535,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(27); - auto tmp = (main_sel_op_emit_l2_to_l1_msg * (-main_sel_op_emit_l2_to_l1_msg + FF(1))); + auto tmp = ((main_sel_op_emit_l2_to_l1_msg * (-main_sel_op_emit_l2_to_l1_msg + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<27>(evals) += tmp; } @@ -539,7 +543,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(28); - auto tmp = (main_sel_op_get_contract_instance * (-main_sel_op_get_contract_instance + FF(1))); + auto tmp = ((main_sel_op_get_contract_instance * (-main_sel_op_get_contract_instance + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -547,7 +551,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(29); - auto tmp = (main_sel_op_sload * (-main_sel_op_sload + FF(1))); + auto tmp = ((main_sel_op_sload * (-main_sel_op_sload + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -555,7 +559,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(30); - auto tmp = (main_sel_op_sstore * (-main_sel_op_sstore + FF(1))); + auto tmp = ((main_sel_op_sstore * (-main_sel_op_sstore + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -563,7 +567,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(31); - auto tmp = (main_sel_op_radix_le * (-main_sel_op_radix_le + FF(1))); + auto tmp = ((main_sel_op_radix_le * (-main_sel_op_radix_le + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<31>(evals) += tmp; } @@ -571,7 +575,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(32); - auto tmp = (main_sel_op_sha256 * (-main_sel_op_sha256 + FF(1))); + auto tmp = ((main_sel_op_sha256 * (-main_sel_op_sha256 + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<32>(evals) += tmp; } @@ -579,7 +583,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(33); - auto tmp = (main_sel_op_poseidon2 * (-main_sel_op_poseidon2 + FF(1))); + auto tmp = ((main_sel_op_poseidon2 * (-main_sel_op_poseidon2 + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<33>(evals) += tmp; } @@ -587,7 +591,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(34); - auto tmp = (main_sel_op_keccak * (-main_sel_op_keccak + FF(1))); + auto tmp = ((main_sel_op_keccak * (-main_sel_op_keccak + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<34>(evals) += tmp; } @@ -595,7 +599,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(35); - auto tmp = (main_sel_op_pedersen * (-main_sel_op_pedersen + FF(1))); + auto tmp = ((main_sel_op_pedersen * (-main_sel_op_pedersen + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<35>(evals) += tmp; } @@ -603,7 +607,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(36); - auto tmp = (main_sel_op_add * (-main_sel_op_add + FF(1))); + auto tmp = ((main_sel_op_add * (-main_sel_op_add + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<36>(evals) += tmp; } @@ -611,7 +615,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(37); - auto tmp = (main_sel_op_sub * (-main_sel_op_sub + FF(1))); + auto tmp = ((main_sel_op_sub * (-main_sel_op_sub + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<37>(evals) += tmp; } @@ -619,7 +623,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(38); - auto tmp = (main_sel_op_mul * (-main_sel_op_mul + FF(1))); + auto tmp = ((main_sel_op_mul * (-main_sel_op_mul + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<38>(evals) += tmp; } @@ -627,7 +631,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(39); - auto tmp = (main_sel_op_div * (-main_sel_op_div + FF(1))); + auto tmp = ((main_sel_op_div * (-main_sel_op_div + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<39>(evals) += tmp; } @@ -635,7 +639,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(40); - auto tmp = (main_sel_op_fdiv * (-main_sel_op_fdiv + FF(1))); + auto tmp = ((main_sel_op_fdiv * (-main_sel_op_fdiv + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<40>(evals) += tmp; } @@ -643,7 +647,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(41); - auto tmp = (main_sel_op_not * (-main_sel_op_not + FF(1))); + auto tmp = ((main_sel_op_not * (-main_sel_op_not + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<41>(evals) += tmp; } @@ -651,7 +655,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(42); - auto tmp = (main_sel_op_eq * (-main_sel_op_eq + FF(1))); + auto tmp = ((main_sel_op_eq * (-main_sel_op_eq + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<42>(evals) += tmp; } @@ -659,7 +663,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(43); - auto tmp = (main_sel_op_and * (-main_sel_op_and + FF(1))); + auto tmp = ((main_sel_op_and * (-main_sel_op_and + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<43>(evals) += tmp; } @@ -667,7 +671,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(44); - auto tmp = (main_sel_op_or * (-main_sel_op_or + FF(1))); + auto tmp = ((main_sel_op_or * (-main_sel_op_or + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<44>(evals) += tmp; } @@ -675,7 +679,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(45); - auto tmp = (main_sel_op_xor * (-main_sel_op_xor + FF(1))); + auto tmp = ((main_sel_op_xor * (-main_sel_op_xor + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<45>(evals) += tmp; } @@ -683,7 +687,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(46); - auto tmp = (main_sel_op_cast * (-main_sel_op_cast + FF(1))); + auto tmp = ((main_sel_op_cast * (-main_sel_op_cast + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<46>(evals) += tmp; } @@ -691,7 +695,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(47); - auto tmp = (main_sel_op_lt * (-main_sel_op_lt + FF(1))); + auto tmp = ((main_sel_op_lt * (-main_sel_op_lt + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<47>(evals) += tmp; } @@ -699,7 +703,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(48); - auto tmp = (main_sel_op_lte * (-main_sel_op_lte + FF(1))); + auto tmp = ((main_sel_op_lte * (-main_sel_op_lte + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<48>(evals) += tmp; } @@ -707,7 +711,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(49); - auto tmp = (main_sel_op_shl * (-main_sel_op_shl + FF(1))); + auto tmp = ((main_sel_op_shl * (-main_sel_op_shl + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<49>(evals) += tmp; } @@ -715,7 +719,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(50); - auto tmp = (main_sel_op_shr * (-main_sel_op_shr + FF(1))); + auto tmp = ((main_sel_op_shr * (-main_sel_op_shr + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<50>(evals) += tmp; } @@ -723,7 +727,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(51); - auto tmp = (main_sel_op_internal_call * (-main_sel_op_internal_call + FF(1))); + auto tmp = ((main_sel_op_internal_call * (-main_sel_op_internal_call + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<51>(evals) += tmp; } @@ -731,7 +735,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(52); - auto tmp = (main_sel_op_internal_return * (-main_sel_op_internal_return + FF(1))); + auto tmp = ((main_sel_op_internal_return * (-main_sel_op_internal_return + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<52>(evals) += tmp; } @@ -739,7 +743,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(53); - auto tmp = (main_sel_op_jump * (-main_sel_op_jump + FF(1))); + auto tmp = ((main_sel_op_jump * (-main_sel_op_jump + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<53>(evals) += tmp; } @@ -747,7 +751,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(54); - auto tmp = (main_sel_op_jumpi * (-main_sel_op_jumpi + FF(1))); + auto tmp = ((main_sel_op_jumpi * (-main_sel_op_jumpi + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<54>(evals) += tmp; } @@ -755,7 +759,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(55); - auto tmp = (main_sel_op_halt * (-main_sel_op_halt + FF(1))); + auto tmp = ((main_sel_op_halt * (-main_sel_op_halt + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<55>(evals) += tmp; } @@ -763,7 +767,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(56); - auto tmp = (main_sel_op_external_call * (-main_sel_op_external_call + FF(1))); + auto tmp = ((main_sel_op_external_call * (-main_sel_op_external_call + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<56>(evals) += tmp; } @@ -771,7 +775,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(57); - auto tmp = (main_sel_op_mov * (-main_sel_op_mov + FF(1))); + auto tmp = ((main_sel_op_mov * (-main_sel_op_mov + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<57>(evals) += tmp; } @@ -779,7 +783,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(58); - auto tmp = (main_sel_op_cmov * (-main_sel_op_cmov + FF(1))); + auto tmp = ((main_sel_op_cmov * (-main_sel_op_cmov + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<58>(evals) += tmp; } @@ -787,7 +791,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(59); - auto tmp = (main_op_err * (-main_op_err + FF(1))); + auto tmp = ((main_op_err * (-main_op_err + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<59>(evals) += tmp; } @@ -795,7 +799,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(60); - auto tmp = (main_tag_err * (-main_tag_err + FF(1))); + auto tmp = ((main_tag_err * (-main_tag_err + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<60>(evals) += tmp; } @@ -803,7 +807,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(61); - auto tmp = (main_id_zero * (-main_id_zero + FF(1))); + auto tmp = ((main_id_zero * (-main_id_zero + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<61>(evals) += tmp; } @@ -811,7 +815,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(62); - auto tmp = (main_sel_mem_op_a * (-main_sel_mem_op_a + FF(1))); + auto tmp = ((main_sel_mem_op_a * (-main_sel_mem_op_a + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<62>(evals) += tmp; } @@ -819,7 +823,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(63); - auto tmp = (main_sel_mem_op_b * (-main_sel_mem_op_b + FF(1))); + auto tmp = ((main_sel_mem_op_b * (-main_sel_mem_op_b + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<63>(evals) += tmp; } @@ -827,7 +831,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(64); - auto tmp = (main_sel_mem_op_c * (-main_sel_mem_op_c + FF(1))); + auto tmp = ((main_sel_mem_op_c * (-main_sel_mem_op_c + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<64>(evals) += tmp; } @@ -835,7 +839,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(65); - auto tmp = (main_sel_mem_op_d * (-main_sel_mem_op_d + FF(1))); + auto tmp = ((main_sel_mem_op_d * (-main_sel_mem_op_d + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<65>(evals) += tmp; } @@ -843,7 +847,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(66); - auto tmp = (main_rwa * (-main_rwa + FF(1))); + auto tmp = ((main_rwa * (-main_rwa + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<66>(evals) += tmp; } @@ -851,7 +855,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(67); - auto tmp = (main_rwb * (-main_rwb + FF(1))); + auto tmp = ((main_rwb * (-main_rwb + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<67>(evals) += tmp; } @@ -859,7 +863,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(68); - auto tmp = (main_rwc * (-main_rwc + FF(1))); + auto tmp = ((main_rwc * (-main_rwc + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<68>(evals) += tmp; } @@ -867,7 +871,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(69); - auto tmp = (main_rwd * (-main_rwd + FF(1))); + auto tmp = ((main_rwd * (-main_rwd + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<69>(evals) += tmp; } @@ -875,7 +879,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(70); - auto tmp = (main_sel_resolve_ind_addr_a * (-main_sel_resolve_ind_addr_a + FF(1))); + auto tmp = ((main_sel_resolve_ind_addr_a * (-main_sel_resolve_ind_addr_a + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<70>(evals) += tmp; } @@ -883,7 +887,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(71); - auto tmp = (main_sel_resolve_ind_addr_b * (-main_sel_resolve_ind_addr_b + FF(1))); + auto tmp = ((main_sel_resolve_ind_addr_b * (-main_sel_resolve_ind_addr_b + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<71>(evals) += tmp; } @@ -891,7 +895,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(72); - auto tmp = (main_sel_resolve_ind_addr_c * (-main_sel_resolve_ind_addr_c + FF(1))); + auto tmp = ((main_sel_resolve_ind_addr_c * (-main_sel_resolve_ind_addr_c + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<72>(evals) += tmp; } @@ -899,7 +903,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(73); - auto tmp = (main_sel_resolve_ind_addr_d * (-main_sel_resolve_ind_addr_d + FF(1))); + auto tmp = ((main_sel_resolve_ind_addr_d * (-main_sel_resolve_ind_addr_d + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<73>(evals) += tmp; } @@ -907,7 +911,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(74); - auto tmp = (((main_sel_op_eq + main_sel_op_lte) + main_sel_op_lt) * (main_w_in_tag - FF(1))); + auto tmp = ((((main_sel_op_eq + main_sel_op_lte) + main_sel_op_lt) * (main_w_in_tag - FF(1))) - FF(0)); tmp *= scaling_factor; std::get<74>(evals) += tmp; } @@ -915,7 +919,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(75); - auto tmp = ((main_sel_op_fdiv * (-main_op_err + FF(1))) * ((main_ic * main_ib) - main_ia)); + auto tmp = (((main_sel_op_fdiv * (-main_op_err + FF(1))) * ((main_ic * main_ib) - main_ia)) - FF(0)); tmp *= scaling_factor; std::get<75>(evals) += tmp; } @@ -923,7 +927,8 @@ template class mainImpl { { Avm_DECLARE_VIEWS(76); - auto tmp = ((main_sel_op_fdiv + main_sel_op_div) * (((main_ib * main_inv) - FF(1)) + main_op_err)); + auto tmp = + (((main_sel_op_fdiv + main_sel_op_div) * (((main_ib * main_inv) - FF(1)) + main_op_err)) - FF(0)); tmp *= scaling_factor; std::get<76>(evals) += tmp; } @@ -931,7 +936,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(77); - auto tmp = (((main_sel_op_fdiv + main_sel_op_div) * main_op_err) * (-main_inv + FF(1))); + auto tmp = ((((main_sel_op_fdiv + main_sel_op_div) * main_op_err) * (-main_inv + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<77>(evals) += tmp; } @@ -939,7 +944,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(78); - auto tmp = (main_sel_op_fdiv * (main_r_in_tag - FF(6))); + auto tmp = ((main_sel_op_fdiv * (main_r_in_tag - FF(6))) - FF(0)); tmp *= scaling_factor; std::get<78>(evals) += tmp; } @@ -947,7 +952,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(79); - auto tmp = (main_sel_op_fdiv * (main_w_in_tag - FF(6))); + auto tmp = ((main_sel_op_fdiv * (main_w_in_tag - FF(6))) - FF(0)); tmp *= scaling_factor; std::get<79>(evals) += tmp; } @@ -955,7 +960,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(80); - auto tmp = (main_op_err * ((main_sel_op_fdiv + main_sel_op_div) - FF(1))); + auto tmp = ((main_op_err * ((main_sel_op_fdiv + main_sel_op_div) - FF(1))) - FF(0)); tmp *= scaling_factor; std::get<80>(evals) += tmp; } @@ -963,16 +968,17 @@ template class mainImpl { { Avm_DECLARE_VIEWS(81); - auto tmp = (((((((((((main_sel_op_sender + main_sel_op_address) + main_sel_op_storage_address) + - main_sel_op_chain_id) + - main_sel_op_version) + - main_sel_op_block_number) + - main_sel_op_coinbase) + - main_sel_op_timestamp) + - main_sel_op_fee_per_l2_gas) + - main_sel_op_fee_per_da_gas) + - main_sel_op_transaction_fee) * - (-main_sel_q_kernel_lookup + FF(1))); + auto tmp = ((((((((((((main_sel_op_sender + main_sel_op_address) + main_sel_op_storage_address) + + main_sel_op_chain_id) + + main_sel_op_version) + + main_sel_op_block_number) + + main_sel_op_coinbase) + + main_sel_op_timestamp) + + main_sel_op_fee_per_l2_gas) + + main_sel_op_fee_per_da_gas) + + main_sel_op_transaction_fee) * + (-main_sel_q_kernel_lookup + FF(1))) - + FF(0)); tmp *= scaling_factor; std::get<81>(evals) += tmp; } @@ -981,12 +987,13 @@ template class mainImpl { Avm_DECLARE_VIEWS(82); auto tmp = - (((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + main_sel_op_nullifier_exists) + - main_sel_op_emit_nullifier) + - main_sel_op_l1_to_l2_msg_exists) + - main_sel_op_emit_unencrypted_log) + - main_sel_op_emit_l2_to_l1_msg) * - (-main_sel_q_kernel_output_lookup + FF(1))); + ((((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + main_sel_op_nullifier_exists) + + main_sel_op_emit_nullifier) + + main_sel_op_l1_to_l2_msg_exists) + + main_sel_op_emit_unencrypted_log) + + main_sel_op_emit_l2_to_l1_msg) * + (-main_sel_q_kernel_output_lookup + FF(1))) - + FF(0)); tmp *= scaling_factor; std::get<82>(evals) += tmp; } @@ -994,7 +1001,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(83); - auto tmp = (main_sel_op_jump * (main_pc_shift - main_ia)); + auto tmp = ((main_sel_op_jump * (main_pc_shift - main_ia)) - FF(0)); tmp *= scaling_factor; std::get<83>(evals) += tmp; } @@ -1002,8 +1009,9 @@ template class mainImpl { { Avm_DECLARE_VIEWS(84); - auto tmp = (main_sel_op_jumpi * (((-main_id_zero + FF(1)) * (main_pc_shift - main_ia)) + - (main_id_zero * ((main_pc_shift - main_pc) - FF(1))))); + auto tmp = ((main_sel_op_jumpi * (((-main_id_zero + FF(1)) * (main_pc_shift - main_ia)) + + (main_id_zero * ((main_pc_shift - main_pc) - FF(1))))) - + FF(0)); tmp *= scaling_factor; std::get<84>(evals) += tmp; } @@ -1012,7 +1020,8 @@ template class mainImpl { Avm_DECLARE_VIEWS(85); auto tmp = - (main_sel_op_internal_call * (main_internal_return_ptr_shift - (main_internal_return_ptr + FF(1)))); + ((main_sel_op_internal_call * (main_internal_return_ptr_shift - (main_internal_return_ptr + FF(1)))) - + FF(0)); tmp *= scaling_factor; std::get<85>(evals) += tmp; } @@ -1020,7 +1029,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(86); - auto tmp = (main_sel_op_internal_call * (main_internal_return_ptr - main_mem_addr_b)); + auto tmp = ((main_sel_op_internal_call * (main_internal_return_ptr - main_mem_addr_b)) - FF(0)); tmp *= scaling_factor; std::get<86>(evals) += tmp; } @@ -1028,7 +1037,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(87); - auto tmp = (main_sel_op_internal_call * (main_pc_shift - main_ia)); + auto tmp = ((main_sel_op_internal_call * (main_pc_shift - main_ia)) - FF(0)); tmp *= scaling_factor; std::get<87>(evals) += tmp; } @@ -1036,7 +1045,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(88); - auto tmp = (main_sel_op_internal_call * ((main_pc + FF(1)) - main_ib)); + auto tmp = ((main_sel_op_internal_call * ((main_pc + FF(1)) - main_ib)) - FF(0)); tmp *= scaling_factor; std::get<88>(evals) += tmp; } @@ -1044,7 +1053,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(89); - auto tmp = (main_sel_op_internal_call * (main_rwb - FF(1))); + auto tmp = ((main_sel_op_internal_call * (main_rwb - FF(1))) - FF(0)); tmp *= scaling_factor; std::get<89>(evals) += tmp; } @@ -1052,7 +1061,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(90); - auto tmp = (main_sel_op_internal_call * (main_sel_mem_op_b - FF(1))); + auto tmp = ((main_sel_op_internal_call * (main_sel_mem_op_b - FF(1))) - FF(0)); tmp *= scaling_factor; std::get<90>(evals) += tmp; } @@ -1061,7 +1070,8 @@ template class mainImpl { Avm_DECLARE_VIEWS(91); auto tmp = - (main_sel_op_internal_return * (main_internal_return_ptr_shift - (main_internal_return_ptr - FF(1)))); + ((main_sel_op_internal_return * (main_internal_return_ptr_shift - (main_internal_return_ptr - FF(1)))) - + FF(0)); tmp *= scaling_factor; std::get<91>(evals) += tmp; } @@ -1069,7 +1079,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(92); - auto tmp = (main_sel_op_internal_return * ((main_internal_return_ptr - FF(1)) - main_mem_addr_a)); + auto tmp = ((main_sel_op_internal_return * ((main_internal_return_ptr - FF(1)) - main_mem_addr_a)) - FF(0)); tmp *= scaling_factor; std::get<92>(evals) += tmp; } @@ -1077,7 +1087,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(93); - auto tmp = (main_sel_op_internal_return * (main_pc_shift - main_ia)); + auto tmp = ((main_sel_op_internal_return * (main_pc_shift - main_ia)) - FF(0)); tmp *= scaling_factor; std::get<93>(evals) += tmp; } @@ -1085,7 +1095,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(94); - auto tmp = (main_sel_op_internal_return * main_rwa); + auto tmp = ((main_sel_op_internal_return * main_rwa) - FF(0)); tmp *= scaling_factor; std::get<94>(evals) += tmp; } @@ -1093,7 +1103,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(95); - auto tmp = (main_sel_op_internal_return * (main_sel_mem_op_a - FF(1))); + auto tmp = ((main_sel_op_internal_return * (main_sel_mem_op_a - FF(1))) - FF(0)); tmp *= scaling_factor; std::get<95>(evals) += tmp; } @@ -1101,42 +1111,43 @@ template class mainImpl { { Avm_DECLARE_VIEWS(96); - auto tmp = - (((((main_sel_gas_accounting_active - - (((((((main_sel_op_fdiv + - ((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + - main_sel_op_not) + - main_sel_op_eq) + - main_sel_op_lt) + - main_sel_op_lte) + - main_sel_op_shr) + - main_sel_op_shl) + - main_sel_op_cast)) + - ((main_sel_op_and + main_sel_op_or) + main_sel_op_xor)) + - (main_sel_op_cmov + main_sel_op_mov)) + - ((((main_sel_op_radix_le + main_sel_op_sha256) + main_sel_op_poseidon2) + main_sel_op_keccak) + - main_sel_op_pedersen)) + - ((((((((((main_sel_op_sender + main_sel_op_address) + main_sel_op_storage_address) + - main_sel_op_chain_id) + - main_sel_op_version) + - main_sel_op_block_number) + - main_sel_op_coinbase) + - main_sel_op_timestamp) + - main_sel_op_fee_per_l2_gas) + - main_sel_op_fee_per_da_gas) + - main_sel_op_transaction_fee)) + - ((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + - main_sel_op_nullifier_exists) + - main_sel_op_emit_nullifier) + - main_sel_op_l1_to_l2_msg_exists) + - main_sel_op_emit_unencrypted_log) + - main_sel_op_emit_l2_to_l1_msg)) + - (main_sel_op_dagasleft + main_sel_op_l2gasleft))) - - (((main_sel_op_jump + main_sel_op_jumpi) + main_sel_op_internal_call) + - main_sel_op_internal_return)) - - main_sel_op_sload) - - main_sel_op_sstore) - - main_sel_mem_op_activate_gas); + auto tmp = ((((((main_sel_gas_accounting_active - + (((((((main_sel_op_fdiv + + ((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + + main_sel_op_not) + + main_sel_op_eq) + + main_sel_op_lt) + + main_sel_op_lte) + + main_sel_op_shr) + + main_sel_op_shl) + + main_sel_op_cast)) + + ((main_sel_op_and + main_sel_op_or) + main_sel_op_xor)) + + (main_sel_op_cmov + main_sel_op_mov)) + + ((((main_sel_op_radix_le + main_sel_op_sha256) + main_sel_op_poseidon2) + + main_sel_op_keccak) + + main_sel_op_pedersen)) + + ((((((((((main_sel_op_sender + main_sel_op_address) + main_sel_op_storage_address) + + main_sel_op_chain_id) + + main_sel_op_version) + + main_sel_op_block_number) + + main_sel_op_coinbase) + + main_sel_op_timestamp) + + main_sel_op_fee_per_l2_gas) + + main_sel_op_fee_per_da_gas) + + main_sel_op_transaction_fee)) + + ((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + + main_sel_op_nullifier_exists) + + main_sel_op_emit_nullifier) + + main_sel_op_l1_to_l2_msg_exists) + + main_sel_op_emit_unencrypted_log) + + main_sel_op_emit_l2_to_l1_msg)) + + (main_sel_op_dagasleft + main_sel_op_l2gasleft))) - + (((main_sel_op_jump + main_sel_op_jumpi) + main_sel_op_internal_call) + + main_sel_op_internal_return)) - + main_sel_op_sload) - + main_sel_op_sstore) - + main_sel_mem_op_activate_gas) - + FF(0)); tmp *= scaling_factor; std::get<96>(evals) += tmp; } @@ -1145,8 +1156,67 @@ template class mainImpl { Avm_DECLARE_VIEWS(97); auto tmp = - ((((-main_sel_first + FF(1)) * (-main_sel_op_halt + FF(1))) * - (((((((main_sel_op_fdiv + + (((((-main_sel_first + FF(1)) * (-main_sel_op_halt + FF(1))) * + (((((((main_sel_op_fdiv + + ((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + + main_sel_op_not) + + main_sel_op_eq) + + main_sel_op_lt) + + main_sel_op_lte) + + main_sel_op_shr) + + main_sel_op_shl) + + main_sel_op_cast)) + + ((main_sel_op_and + main_sel_op_or) + main_sel_op_xor)) + + (main_sel_op_cmov + main_sel_op_mov)) + + ((((main_sel_op_radix_le + main_sel_op_sha256) + main_sel_op_poseidon2) + main_sel_op_keccak) + + main_sel_op_pedersen)) + + ((((((((((main_sel_op_sender + main_sel_op_address) + main_sel_op_storage_address) + + main_sel_op_chain_id) + + main_sel_op_version) + + main_sel_op_block_number) + + main_sel_op_coinbase) + + main_sel_op_timestamp) + + main_sel_op_fee_per_l2_gas) + + main_sel_op_fee_per_da_gas) + + main_sel_op_transaction_fee)) + + ((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + main_sel_op_nullifier_exists) + + main_sel_op_emit_nullifier) + + main_sel_op_l1_to_l2_msg_exists) + + main_sel_op_emit_unencrypted_log) + + main_sel_op_emit_l2_to_l1_msg)) + + (main_sel_op_dagasleft + main_sel_op_l2gasleft))) * + (main_pc_shift - (main_pc + FF(1)))) - + FF(0)); + tmp *= scaling_factor; + std::get<97>(evals) += tmp; + } + // Contribution 98 + { + Avm_DECLARE_VIEWS(98); + + auto tmp = + (((-(((main_sel_first + main_sel_op_internal_call) + main_sel_op_internal_return) + main_sel_op_halt) + + FF(1)) * + (main_internal_return_ptr_shift - main_internal_return_ptr)) - + FF(0)); + tmp *= scaling_factor; + std::get<98>(evals) += tmp; + } + // Contribution 99 + { + Avm_DECLARE_VIEWS(99); + + auto tmp = + (((main_sel_op_internal_call + main_sel_op_internal_return) * (main_space_id - FF(255))) - FF(0)); + tmp *= scaling_factor; + std::get<99>(evals) += tmp; + } + // Contribution 100 + { + Avm_DECLARE_VIEWS(100); + + auto tmp = + (((((((((main_sel_op_fdiv + ((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + main_sel_op_not) + main_sel_op_eq) + @@ -1173,64 +1243,9 @@ template class mainImpl { main_sel_op_l1_to_l2_msg_exists) + main_sel_op_emit_unencrypted_log) + main_sel_op_emit_l2_to_l1_msg)) + - (main_sel_op_dagasleft + main_sel_op_l2gasleft))) * - (main_pc_shift - (main_pc + FF(1)))); - tmp *= scaling_factor; - std::get<97>(evals) += tmp; - } - // Contribution 98 - { - Avm_DECLARE_VIEWS(98); - - auto tmp = - ((-(((main_sel_first + main_sel_op_internal_call) + main_sel_op_internal_return) + main_sel_op_halt) + - FF(1)) * - (main_internal_return_ptr_shift - main_internal_return_ptr)); - tmp *= scaling_factor; - std::get<98>(evals) += tmp; - } - // Contribution 99 - { - Avm_DECLARE_VIEWS(99); - - auto tmp = ((main_sel_op_internal_call + main_sel_op_internal_return) * (main_space_id - FF(255))); - tmp *= scaling_factor; - std::get<99>(evals) += tmp; - } - // Contribution 100 - { - Avm_DECLARE_VIEWS(100); - - auto tmp = - ((((((((main_sel_op_fdiv + - ((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + - main_sel_op_not) + - main_sel_op_eq) + - main_sel_op_lt) + - main_sel_op_lte) + - main_sel_op_shr) + - main_sel_op_shl) + - main_sel_op_cast)) + - ((main_sel_op_and + main_sel_op_or) + main_sel_op_xor)) + - (main_sel_op_cmov + main_sel_op_mov)) + - ((((main_sel_op_radix_le + main_sel_op_sha256) + main_sel_op_poseidon2) + main_sel_op_keccak) + - main_sel_op_pedersen)) + - ((((((((((main_sel_op_sender + main_sel_op_address) + main_sel_op_storage_address) + - main_sel_op_chain_id) + - main_sel_op_version) + - main_sel_op_block_number) + - main_sel_op_coinbase) + - main_sel_op_timestamp) + - main_sel_op_fee_per_l2_gas) + - main_sel_op_fee_per_da_gas) + - main_sel_op_transaction_fee)) + - ((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + main_sel_op_nullifier_exists) + - main_sel_op_emit_nullifier) + - main_sel_op_l1_to_l2_msg_exists) + - main_sel_op_emit_unencrypted_log) + - main_sel_op_emit_l2_to_l1_msg)) + - (main_sel_op_dagasleft + main_sel_op_l2gasleft)) * - (main_call_ptr - main_space_id)); + (main_sel_op_dagasleft + main_sel_op_l2gasleft)) * + (main_call_ptr - main_space_id)) - + FF(0)); tmp *= scaling_factor; std::get<100>(evals) += tmp; } @@ -1238,7 +1253,8 @@ template class mainImpl { { Avm_DECLARE_VIEWS(101); - auto tmp = ((main_sel_op_cmov + main_sel_op_jumpi) * (((main_id * main_inv) - FF(1)) + main_id_zero)); + auto tmp = + (((main_sel_op_cmov + main_sel_op_jumpi) * (((main_id * main_inv) - FF(1)) + main_id_zero)) - FF(0)); tmp *= scaling_factor; std::get<101>(evals) += tmp; } @@ -1246,7 +1262,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(102); - auto tmp = (((main_sel_op_cmov + main_sel_op_jumpi) * main_id_zero) * (-main_inv + FF(1))); + auto tmp = ((((main_sel_op_cmov + main_sel_op_jumpi) * main_id_zero) * (-main_inv + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<102>(evals) += tmp; } @@ -1270,7 +1286,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(105); - auto tmp = (main_sel_mov_ia_to_ic * (main_ia - main_ic)); + auto tmp = ((main_sel_mov_ia_to_ic * (main_ia - main_ic)) - FF(0)); tmp *= scaling_factor; std::get<105>(evals) += tmp; } @@ -1278,7 +1294,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(106); - auto tmp = (main_sel_mov_ib_to_ic * (main_ib - main_ic)); + auto tmp = ((main_sel_mov_ib_to_ic * (main_ib - main_ic)) - FF(0)); tmp *= scaling_factor; std::get<106>(evals) += tmp; } @@ -1286,7 +1302,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(107); - auto tmp = ((main_sel_op_mov + main_sel_op_cmov) * (main_r_in_tag - main_w_in_tag)); + auto tmp = (((main_sel_op_mov + main_sel_op_cmov) * (main_r_in_tag - main_w_in_tag)) - FF(0)); tmp *= scaling_factor; std::get<107>(evals) += tmp; } @@ -1313,13 +1329,14 @@ template class mainImpl { Avm_DECLARE_VIEWS(109); auto tmp = - ((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + main_sel_op_not) + - main_sel_op_eq) + - main_sel_op_lt) + - main_sel_op_lte) + - main_sel_op_shr) + - main_sel_op_shl) * - (main_alu_in_tag - main_r_in_tag)); + (((((((((((main_sel_op_add + main_sel_op_sub) + main_sel_op_mul) + main_sel_op_div) + main_sel_op_not) + + main_sel_op_eq) + + main_sel_op_lt) + + main_sel_op_lte) + + main_sel_op_shr) + + main_sel_op_shl) * + (main_alu_in_tag - main_r_in_tag)) - + FF(0)); tmp *= scaling_factor; std::get<109>(evals) += tmp; } @@ -1327,7 +1344,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(110); - auto tmp = (main_sel_op_cast * (main_alu_in_tag - main_w_in_tag)); + auto tmp = ((main_sel_op_cast * (main_alu_in_tag - main_w_in_tag)) - FF(0)); tmp *= scaling_factor; std::get<110>(evals) += tmp; } @@ -1335,7 +1352,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(111); - auto tmp = (main_sel_op_l2gasleft * (main_ia - main_l2_gas_remaining_shift)); + auto tmp = ((main_sel_op_l2gasleft * (main_ia - main_l2_gas_remaining_shift)) - FF(0)); tmp *= scaling_factor; std::get<111>(evals) += tmp; } @@ -1343,7 +1360,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(112); - auto tmp = (main_sel_op_dagasleft * (main_ia - main_da_gas_remaining_shift)); + auto tmp = ((main_sel_op_dagasleft * (main_ia - main_da_gas_remaining_shift)) - FF(0)); tmp *= scaling_factor; std::get<112>(evals) += tmp; } @@ -1351,7 +1368,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(113); - auto tmp = (main_sel_op_sender * (kernel_kernel_in_offset - FF(0))); + auto tmp = ((main_sel_op_sender * (kernel_kernel_in_offset - FF(0))) - FF(0)); tmp *= scaling_factor; std::get<113>(evals) += tmp; } @@ -1359,7 +1376,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(114); - auto tmp = (main_sel_op_address * (kernel_kernel_in_offset - FF(1))); + auto tmp = ((main_sel_op_address * (kernel_kernel_in_offset - FF(1))) - FF(0)); tmp *= scaling_factor; std::get<114>(evals) += tmp; } @@ -1367,7 +1384,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(115); - auto tmp = (main_sel_op_storage_address * (kernel_kernel_in_offset - FF(2))); + auto tmp = ((main_sel_op_storage_address * (kernel_kernel_in_offset - FF(2))) - FF(0)); tmp *= scaling_factor; std::get<115>(evals) += tmp; } @@ -1375,7 +1392,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(116); - auto tmp = (main_sel_op_fee_per_da_gas * (kernel_kernel_in_offset - FF(35))); + auto tmp = ((main_sel_op_fee_per_da_gas * (kernel_kernel_in_offset - FF(35))) - FF(0)); tmp *= scaling_factor; std::get<116>(evals) += tmp; } @@ -1383,7 +1400,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(117); - auto tmp = (main_sel_op_fee_per_l2_gas * (kernel_kernel_in_offset - FF(36))); + auto tmp = ((main_sel_op_fee_per_l2_gas * (kernel_kernel_in_offset - FF(36))) - FF(0)); tmp *= scaling_factor; std::get<117>(evals) += tmp; } @@ -1391,7 +1408,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(118); - auto tmp = (main_sel_op_transaction_fee * (kernel_kernel_in_offset - FF(40))); + auto tmp = ((main_sel_op_transaction_fee * (kernel_kernel_in_offset - FF(40))) - FF(0)); tmp *= scaling_factor; std::get<118>(evals) += tmp; } @@ -1399,7 +1416,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(119); - auto tmp = (main_sel_op_chain_id * (kernel_kernel_in_offset - FF(29))); + auto tmp = ((main_sel_op_chain_id * (kernel_kernel_in_offset - FF(29))) - FF(0)); tmp *= scaling_factor; std::get<119>(evals) += tmp; } @@ -1407,7 +1424,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(120); - auto tmp = (main_sel_op_version * (kernel_kernel_in_offset - FF(30))); + auto tmp = ((main_sel_op_version * (kernel_kernel_in_offset - FF(30))) - FF(0)); tmp *= scaling_factor; std::get<120>(evals) += tmp; } @@ -1415,7 +1432,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(121); - auto tmp = (main_sel_op_block_number * (kernel_kernel_in_offset - FF(31))); + auto tmp = ((main_sel_op_block_number * (kernel_kernel_in_offset - FF(31))) - FF(0)); tmp *= scaling_factor; std::get<121>(evals) += tmp; } @@ -1423,7 +1440,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(122); - auto tmp = (main_sel_op_coinbase * (kernel_kernel_in_offset - FF(33))); + auto tmp = ((main_sel_op_coinbase * (kernel_kernel_in_offset - FF(33))) - FF(0)); tmp *= scaling_factor; std::get<122>(evals) += tmp; } @@ -1431,7 +1448,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(123); - auto tmp = (main_sel_op_timestamp * (kernel_kernel_in_offset - FF(32))); + auto tmp = ((main_sel_op_timestamp * (kernel_kernel_in_offset - FF(32))) - FF(0)); tmp *= scaling_factor; std::get<123>(evals) += tmp; } @@ -1439,8 +1456,9 @@ template class mainImpl { { Avm_DECLARE_VIEWS(124); - auto tmp = (main_sel_op_note_hash_exists * - (kernel_kernel_out_offset - (kernel_note_hash_exist_write_offset + FF(0)))); + auto tmp = ((main_sel_op_note_hash_exists * + (kernel_kernel_out_offset - (kernel_note_hash_exist_write_offset + FF(0)))) - + FF(0)); tmp *= scaling_factor; std::get<124>(evals) += tmp; } @@ -1448,7 +1466,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(125); - auto tmp = (main_sel_first * kernel_note_hash_exist_write_offset); + auto tmp = ((main_sel_first * kernel_note_hash_exist_write_offset) - FF(0)); tmp *= scaling_factor; std::get<125>(evals) += tmp; } @@ -1456,8 +1474,9 @@ template class mainImpl { { Avm_DECLARE_VIEWS(126); - auto tmp = (main_sel_op_emit_note_hash * - (kernel_kernel_out_offset - (kernel_emit_note_hash_write_offset + FF(176)))); + auto tmp = ((main_sel_op_emit_note_hash * + (kernel_kernel_out_offset - (kernel_emit_note_hash_write_offset + FF(176)))) - + FF(0)); tmp *= scaling_factor; std::get<126>(evals) += tmp; } @@ -1465,7 +1484,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(127); - auto tmp = (main_sel_first * kernel_emit_note_hash_write_offset); + auto tmp = ((main_sel_first * kernel_emit_note_hash_write_offset) - FF(0)); tmp *= scaling_factor; std::get<127>(evals) += tmp; } @@ -1473,10 +1492,11 @@ template class mainImpl { { Avm_DECLARE_VIEWS(128); - auto tmp = (main_sel_op_nullifier_exists * - (kernel_kernel_out_offset - - ((main_ib * (kernel_nullifier_exists_write_offset + FF(32))) + - ((-main_ib + FF(1)) * (kernel_nullifier_non_exists_write_offset + FF(64)))))); + auto tmp = ((main_sel_op_nullifier_exists * + (kernel_kernel_out_offset - + ((main_ib * (kernel_nullifier_exists_write_offset + FF(32))) + + ((-main_ib + FF(1)) * (kernel_nullifier_non_exists_write_offset + FF(64)))))) - + FF(0)); tmp *= scaling_factor; std::get<128>(evals) += tmp; } @@ -1484,7 +1504,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(129); - auto tmp = (main_sel_first * kernel_nullifier_exists_write_offset); + auto tmp = ((main_sel_first * kernel_nullifier_exists_write_offset) - FF(0)); tmp *= scaling_factor; std::get<129>(evals) += tmp; } @@ -1492,7 +1512,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(130); - auto tmp = (main_sel_first * kernel_nullifier_non_exists_write_offset); + auto tmp = ((main_sel_first * kernel_nullifier_non_exists_write_offset) - FF(0)); tmp *= scaling_factor; std::get<130>(evals) += tmp; } @@ -1500,8 +1520,9 @@ template class mainImpl { { Avm_DECLARE_VIEWS(131); - auto tmp = (main_sel_op_emit_nullifier * - (kernel_kernel_out_offset - (kernel_emit_nullifier_write_offset + FF(192)))); + auto tmp = ((main_sel_op_emit_nullifier * + (kernel_kernel_out_offset - (kernel_emit_nullifier_write_offset + FF(192)))) - + FF(0)); tmp *= scaling_factor; std::get<131>(evals) += tmp; } @@ -1509,7 +1530,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(132); - auto tmp = (main_sel_first * kernel_emit_nullifier_write_offset); + auto tmp = ((main_sel_first * kernel_emit_nullifier_write_offset) - FF(0)); tmp *= scaling_factor; std::get<132>(evals) += tmp; } @@ -1517,8 +1538,9 @@ template class mainImpl { { Avm_DECLARE_VIEWS(133); - auto tmp = (main_sel_op_l1_to_l2_msg_exists * - (kernel_kernel_out_offset - (kernel_l1_to_l2_msg_exists_write_offset + FF(96)))); + auto tmp = ((main_sel_op_l1_to_l2_msg_exists * + (kernel_kernel_out_offset - (kernel_l1_to_l2_msg_exists_write_offset + FF(96)))) - + FF(0)); tmp *= scaling_factor; std::get<133>(evals) += tmp; } @@ -1526,7 +1548,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(134); - auto tmp = (main_sel_first * kernel_l1_to_l2_msg_exists_write_offset); + auto tmp = ((main_sel_first * kernel_l1_to_l2_msg_exists_write_offset) - FF(0)); tmp *= scaling_factor; std::get<134>(evals) += tmp; } @@ -1534,8 +1556,9 @@ template class mainImpl { { Avm_DECLARE_VIEWS(135); - auto tmp = (main_sel_op_emit_unencrypted_log * - (kernel_kernel_out_offset - (kernel_emit_unencrypted_log_write_offset + FF(210)))); + auto tmp = ((main_sel_op_emit_unencrypted_log * + (kernel_kernel_out_offset - (kernel_emit_unencrypted_log_write_offset + FF(210)))) - + FF(0)); tmp *= scaling_factor; std::get<135>(evals) += tmp; } @@ -1543,7 +1566,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(136); - auto tmp = (main_sel_first * kernel_emit_unencrypted_log_write_offset); + auto tmp = ((main_sel_first * kernel_emit_unencrypted_log_write_offset) - FF(0)); tmp *= scaling_factor; std::get<136>(evals) += tmp; } @@ -1551,8 +1574,9 @@ template class mainImpl { { Avm_DECLARE_VIEWS(137); - auto tmp = (main_sel_op_emit_l2_to_l1_msg * - (kernel_kernel_out_offset - (kernel_emit_l2_to_l1_msg_write_offset + FF(208)))); + auto tmp = ((main_sel_op_emit_l2_to_l1_msg * + (kernel_kernel_out_offset - (kernel_emit_l2_to_l1_msg_write_offset + FF(208)))) - + FF(0)); tmp *= scaling_factor; std::get<137>(evals) += tmp; } @@ -1560,7 +1584,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(138); - auto tmp = (main_sel_first * kernel_emit_l2_to_l1_msg_write_offset); + auto tmp = ((main_sel_first * kernel_emit_l2_to_l1_msg_write_offset) - FF(0)); tmp *= scaling_factor; std::get<138>(evals) += tmp; } @@ -1568,7 +1592,8 @@ template class mainImpl { { Avm_DECLARE_VIEWS(139); - auto tmp = (main_sel_op_sload * (kernel_kernel_out_offset - (kernel_sload_write_offset + FF(144)))); + auto tmp = + ((main_sel_op_sload * (kernel_kernel_out_offset - (kernel_sload_write_offset + FF(144)))) - FF(0)); tmp *= scaling_factor; std::get<139>(evals) += tmp; } @@ -1576,7 +1601,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(140); - auto tmp = (main_sel_first * kernel_sload_write_offset); + auto tmp = ((main_sel_first * kernel_sload_write_offset) - FF(0)); tmp *= scaling_factor; std::get<140>(evals) += tmp; } @@ -1584,7 +1609,8 @@ template class mainImpl { { Avm_DECLARE_VIEWS(141); - auto tmp = (main_sel_op_sstore * (kernel_kernel_out_offset - (kernel_sstore_write_offset + FF(112)))); + auto tmp = + ((main_sel_op_sstore * (kernel_kernel_out_offset - (kernel_sstore_write_offset + FF(112)))) - FF(0)); tmp *= scaling_factor; std::get<141>(evals) += tmp; } @@ -1592,7 +1618,7 @@ template class mainImpl { { Avm_DECLARE_VIEWS(142); - auto tmp = (main_sel_first * kernel_sstore_write_offset); + auto tmp = ((main_sel_first * kernel_sstore_write_offset) - FF(0)); tmp *= scaling_factor; std::get<142>(evals) += tmp; } @@ -1601,12 +1627,13 @@ template class mainImpl { Avm_DECLARE_VIEWS(143); auto tmp = - (((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + main_sel_op_nullifier_exists) + - main_sel_op_emit_nullifier) + - main_sel_op_l1_to_l2_msg_exists) + - main_sel_op_emit_unencrypted_log) + - main_sel_op_emit_l2_to_l1_msg) * - (kernel_side_effect_counter_shift - (kernel_side_effect_counter + FF(1)))); + ((((((((main_sel_op_note_hash_exists + main_sel_op_emit_note_hash) + main_sel_op_nullifier_exists) + + main_sel_op_emit_nullifier) + + main_sel_op_l1_to_l2_msg_exists) + + main_sel_op_emit_unencrypted_log) + + main_sel_op_emit_l2_to_l1_msg) * + (kernel_side_effect_counter_shift - (kernel_side_effect_counter + FF(1)))) - + FF(0)); tmp *= scaling_factor; std::get<143>(evals) += tmp; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/mem.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/mem.hpp index 8b1c6dcfe57..ea5a125887f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/mem.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/mem.hpp @@ -126,7 +126,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (mem_lastAccess * (-mem_lastAccess + FF(1))); + auto tmp = ((mem_lastAccess * (-mem_lastAccess + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<0>(evals) += tmp; } @@ -134,7 +134,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(1); - auto tmp = (mem_last * (-mem_last + FF(1))); + auto tmp = ((mem_last * (-mem_last + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<1>(evals) += tmp; } @@ -142,7 +142,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(2); - auto tmp = (mem_rw * (-mem_rw + FF(1))); + auto tmp = ((mem_rw * (-mem_rw + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<2>(evals) += tmp; } @@ -150,7 +150,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(3); - auto tmp = (mem_tag_err * (-mem_tag_err + FF(1))); + auto tmp = ((mem_tag_err * (-mem_tag_err + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<3>(evals) += tmp; } @@ -158,7 +158,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(4); - auto tmp = (mem_sel_op_a * (-mem_sel_op_a + FF(1))); + auto tmp = ((mem_sel_op_a * (-mem_sel_op_a + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<4>(evals) += tmp; } @@ -166,7 +166,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(5); - auto tmp = (mem_sel_op_b * (-mem_sel_op_b + FF(1))); + auto tmp = ((mem_sel_op_b * (-mem_sel_op_b + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<5>(evals) += tmp; } @@ -174,7 +174,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(6); - auto tmp = (mem_sel_op_c * (-mem_sel_op_c + FF(1))); + auto tmp = ((mem_sel_op_c * (-mem_sel_op_c + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<6>(evals) += tmp; } @@ -182,7 +182,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(7); - auto tmp = (mem_sel_op_d * (-mem_sel_op_d + FF(1))); + auto tmp = ((mem_sel_op_d * (-mem_sel_op_d + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<7>(evals) += tmp; } @@ -190,7 +190,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(8); - auto tmp = (mem_sel_resolve_ind_addr_a * (-mem_sel_resolve_ind_addr_a + FF(1))); + auto tmp = ((mem_sel_resolve_ind_addr_a * (-mem_sel_resolve_ind_addr_a + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<8>(evals) += tmp; } @@ -198,7 +198,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(9); - auto tmp = (mem_sel_resolve_ind_addr_b * (-mem_sel_resolve_ind_addr_b + FF(1))); + auto tmp = ((mem_sel_resolve_ind_addr_b * (-mem_sel_resolve_ind_addr_b + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<9>(evals) += tmp; } @@ -206,7 +206,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(10); - auto tmp = (mem_sel_resolve_ind_addr_c * (-mem_sel_resolve_ind_addr_c + FF(1))); + auto tmp = ((mem_sel_resolve_ind_addr_c * (-mem_sel_resolve_ind_addr_c + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<10>(evals) += tmp; } @@ -214,7 +214,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(11); - auto tmp = (mem_sel_resolve_ind_addr_d * (-mem_sel_resolve_ind_addr_d + FF(1))); + auto tmp = ((mem_sel_resolve_ind_addr_d * (-mem_sel_resolve_ind_addr_d + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<11>(evals) += tmp; } @@ -235,7 +235,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(13); - auto tmp = (mem_sel_mem * (mem_sel_mem - FF(1))); + auto tmp = ((mem_sel_mem * (mem_sel_mem - FF(1))) - FF(0)); tmp *= scaling_factor; std::get<13>(evals) += tmp; } @@ -243,7 +243,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(14); - auto tmp = (((-main_sel_first + FF(1)) * mem_sel_mem_shift) * (-mem_sel_mem + FF(1))); + auto tmp = ((((-main_sel_first + FF(1)) * mem_sel_mem_shift) * (-mem_sel_mem + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<14>(evals) += tmp; } @@ -251,7 +251,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(15); - auto tmp = (main_sel_first * mem_sel_mem); + auto tmp = ((main_sel_first * mem_sel_mem) - FF(0)); tmp *= scaling_factor; std::get<15>(evals) += tmp; } @@ -259,7 +259,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(16); - auto tmp = (((-mem_last + FF(1)) * mem_sel_mem) * (-mem_sel_mem_shift + FF(1))); + auto tmp = ((((-mem_last + FF(1)) * mem_sel_mem) * (-mem_sel_mem_shift + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<16>(evals) += tmp; } @@ -302,7 +302,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(20); - auto tmp = (main_sel_first * (-mem_lastAccess + FF(1))); + auto tmp = ((main_sel_first * (-mem_lastAccess + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<20>(evals) += tmp; } @@ -310,7 +310,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(21); - auto tmp = ((-mem_lastAccess + FF(1)) * (mem_glob_addr_shift - mem_glob_addr)); + auto tmp = (((-mem_lastAccess + FF(1)) * (mem_glob_addr_shift - mem_glob_addr)) - FF(0)); tmp *= scaling_factor; std::get<21>(evals) += tmp; } @@ -318,11 +318,12 @@ template class memImpl { { Avm_DECLARE_VIEWS(22); - auto tmp = (mem_sel_rng_chk * (((((mem_lastAccess * (mem_glob_addr_shift - mem_glob_addr)) + - ((-mem_lastAccess + FF(1)) * (mem_tsp_shift - mem_tsp))) - - (mem_diff_hi * FF(4294967296UL))) - - (mem_diff_mid * FF(65536))) - - mem_diff_lo)); + auto tmp = ((mem_sel_rng_chk * (((((mem_lastAccess * (mem_glob_addr_shift - mem_glob_addr)) + + ((-mem_lastAccess + FF(1)) * (mem_tsp_shift - mem_tsp))) - + (mem_diff_hi * FF(4294967296UL))) - + (mem_diff_mid * FF(65536))) - + mem_diff_lo)) - + FF(0)); tmp *= scaling_factor; std::get<22>(evals) += tmp; } @@ -330,7 +331,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(23); - auto tmp = (((-mem_lastAccess + FF(1)) * (-mem_rw_shift + FF(1))) * (mem_val_shift - mem_val)); + auto tmp = ((((-mem_lastAccess + FF(1)) * (-mem_rw_shift + FF(1))) * (mem_val_shift - mem_val)) - FF(0)); tmp *= scaling_factor; std::get<23>(evals) += tmp; } @@ -338,7 +339,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(24); - auto tmp = (((-mem_lastAccess + FF(1)) * (-mem_rw_shift + FF(1))) * (mem_tag_shift - mem_tag)); + auto tmp = ((((-mem_lastAccess + FF(1)) * (-mem_rw_shift + FF(1))) * (mem_tag_shift - mem_tag)) - FF(0)); tmp *= scaling_factor; std::get<24>(evals) += tmp; } @@ -346,7 +347,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(25); - auto tmp = ((mem_lastAccess * (-mem_rw_shift + FF(1))) * mem_val_shift); + auto tmp = (((mem_lastAccess * (-mem_rw_shift + FF(1))) * mem_val_shift) - FF(0)); tmp *= scaling_factor; std::get<25>(evals) += tmp; } @@ -364,8 +365,9 @@ template class memImpl { { Avm_DECLARE_VIEWS(27); - auto tmp = (((-mem_skip_check_tag + FF(1)) * (-mem_rw + FF(1))) * - (((mem_r_in_tag - mem_tag) * (-mem_one_min_inv + FF(1))) - mem_tag_err)); + auto tmp = ((((-mem_skip_check_tag + FF(1)) * (-mem_rw + FF(1))) * + (((mem_r_in_tag - mem_tag) * (-mem_one_min_inv + FF(1))) - mem_tag_err)) - + FF(0)); tmp *= scaling_factor; std::get<27>(evals) += tmp; } @@ -373,7 +375,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(28); - auto tmp = ((-mem_tag_err + FF(1)) * mem_one_min_inv); + auto tmp = (((-mem_tag_err + FF(1)) * mem_one_min_inv) - FF(0)); tmp *= scaling_factor; std::get<28>(evals) += tmp; } @@ -381,7 +383,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(29); - auto tmp = ((mem_skip_check_tag + mem_rw) * mem_tag_err); + auto tmp = (((mem_skip_check_tag + mem_rw) * mem_tag_err) - FF(0)); tmp *= scaling_factor; std::get<29>(evals) += tmp; } @@ -389,7 +391,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(30); - auto tmp = (mem_rw * (mem_w_in_tag - mem_tag)); + auto tmp = ((mem_rw * (mem_w_in_tag - mem_tag)) - FF(0)); tmp *= scaling_factor; std::get<30>(evals) += tmp; } @@ -397,7 +399,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(31); - auto tmp = (mem_rw * mem_tag_err); + auto tmp = ((mem_rw * mem_tag_err) - FF(0)); tmp *= scaling_factor; std::get<31>(evals) += tmp; } @@ -405,7 +407,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(32); - auto tmp = (mem_sel_resolve_ind_addr_a * (mem_r_in_tag - FF(3))); + auto tmp = ((mem_sel_resolve_ind_addr_a * (mem_r_in_tag - FF(3))) - FF(0)); tmp *= scaling_factor; std::get<32>(evals) += tmp; } @@ -413,7 +415,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(33); - auto tmp = (mem_sel_resolve_ind_addr_b * (mem_r_in_tag - FF(3))); + auto tmp = ((mem_sel_resolve_ind_addr_b * (mem_r_in_tag - FF(3))) - FF(0)); tmp *= scaling_factor; std::get<33>(evals) += tmp; } @@ -421,7 +423,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(34); - auto tmp = (mem_sel_resolve_ind_addr_c * (mem_r_in_tag - FF(3))); + auto tmp = ((mem_sel_resolve_ind_addr_c * (mem_r_in_tag - FF(3))) - FF(0)); tmp *= scaling_factor; std::get<34>(evals) += tmp; } @@ -429,7 +431,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(35); - auto tmp = (mem_sel_resolve_ind_addr_d * (mem_r_in_tag - FF(3))); + auto tmp = ((mem_sel_resolve_ind_addr_d * (mem_r_in_tag - FF(3))) - FF(0)); tmp *= scaling_factor; std::get<35>(evals) += tmp; } @@ -437,7 +439,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(36); - auto tmp = (mem_sel_resolve_ind_addr_a * mem_rw); + auto tmp = ((mem_sel_resolve_ind_addr_a * mem_rw) - FF(0)); tmp *= scaling_factor; std::get<36>(evals) += tmp; } @@ -445,7 +447,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(37); - auto tmp = (mem_sel_resolve_ind_addr_b * mem_rw); + auto tmp = ((mem_sel_resolve_ind_addr_b * mem_rw) - FF(0)); tmp *= scaling_factor; std::get<37>(evals) += tmp; } @@ -453,7 +455,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(38); - auto tmp = (mem_sel_resolve_ind_addr_c * mem_rw); + auto tmp = ((mem_sel_resolve_ind_addr_c * mem_rw) - FF(0)); tmp *= scaling_factor; std::get<38>(evals) += tmp; } @@ -461,7 +463,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(39); - auto tmp = (mem_sel_resolve_ind_addr_d * mem_rw); + auto tmp = ((mem_sel_resolve_ind_addr_d * mem_rw) - FF(0)); tmp *= scaling_factor; std::get<39>(evals) += tmp; } @@ -469,7 +471,7 @@ template class memImpl { { Avm_DECLARE_VIEWS(40); - auto tmp = ((mem_sel_mov_ia_to_ic + mem_sel_mov_ib_to_ic) * mem_tag_err); + auto tmp = (((mem_sel_mov_ia_to_ic + mem_sel_mov_ib_to_ic) * mem_tag_err) - FF(0)); tmp *= scaling_factor; std::get<40>(evals) += tmp; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/pedersen.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/pedersen.hpp index d09722720e9..eb73ea8dfdd 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/pedersen.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/pedersen.hpp @@ -37,7 +37,7 @@ template class pedersenImpl { { Avm_DECLARE_VIEWS(0); - auto tmp = (pedersen_sel_pedersen * (-pedersen_sel_pedersen + FF(1))); + auto tmp = ((pedersen_sel_pedersen * (-pedersen_sel_pedersen + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<0>(evals) += tmp; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/poseidon2.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/poseidon2.hpp index a758f8333b2..1f6d384a3f7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/poseidon2.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/poseidon2.hpp @@ -37,7 +37,7 @@ template class poseidon2Impl { { Avm_DECLARE_VIEWS(0); - auto tmp = (poseidon2_sel_poseidon_perm * (-poseidon2_sel_poseidon_perm + FF(1))); + auto tmp = ((poseidon2_sel_poseidon_perm * (-poseidon2_sel_poseidon_perm + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<0>(evals) += tmp; } diff --git a/barretenberg/cpp/src/barretenberg/relations/generated/avm/sha256.hpp b/barretenberg/cpp/src/barretenberg/relations/generated/avm/sha256.hpp index 189cbb7c699..d77d4d69f67 100644 --- a/barretenberg/cpp/src/barretenberg/relations/generated/avm/sha256.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/generated/avm/sha256.hpp @@ -37,7 +37,7 @@ template class sha256Impl { { Avm_DECLARE_VIEWS(0); - auto tmp = (sha256_sel_sha256_compression * (-sha256_sel_sha256_compression + FF(1))); + auto tmp = ((sha256_sel_sha256_compression * (-sha256_sel_sha256_compression + FF(1))) - FF(0)); tmp *= scaling_factor; std::get<0>(evals) += tmp; } diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp index a0db02764b3..7d58df8071a 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp @@ -20,6 +20,10 @@ template std::vector AvmFullRow::names() { return { "main_clk", "main_sel_first", + "kernel_kernel_inputs", + "kernel_kernel_value_out", + "kernel_kernel_side_effect_out", + "kernel_kernel_metadata_out", "alu_a_hi", "alu_a_lo", "alu_b_hi", @@ -140,11 +144,7 @@ template std::vector AvmFullRow::names() "kernel_emit_nullifier_write_offset", "kernel_emit_unencrypted_log_write_offset", "kernel_kernel_in_offset", - "kernel_kernel_inputs", - "kernel_kernel_metadata_out", "kernel_kernel_out_offset", - "kernel_kernel_side_effect_out", - "kernel_kernel_value_out", "kernel_l1_to_l2_msg_exists_write_offset", "kernel_note_hash_exist_write_offset", "kernel_nullifier_exists_write_offset", @@ -410,18 +410,20 @@ template std::ostream& operator<<(std::ostream& os, AvmFullRow { return os << field_to_string(row.main_clk) << "," << field_to_string(row.main_sel_first) << "," - << field_to_string(row.alu_a_hi) << "," << field_to_string(row.alu_a_lo) << "," - << field_to_string(row.alu_b_hi) << "," << field_to_string(row.alu_b_lo) << "," - << field_to_string(row.alu_borrow) << "," << field_to_string(row.alu_cf) << "," - << field_to_string(row.alu_clk) << "," << field_to_string(row.alu_cmp_rng_ctr) << "," - << field_to_string(row.alu_div_u16_r0) << "," << field_to_string(row.alu_div_u16_r1) << "," - << field_to_string(row.alu_div_u16_r2) << "," << field_to_string(row.alu_div_u16_r3) << "," - << field_to_string(row.alu_div_u16_r4) << "," << field_to_string(row.alu_div_u16_r5) << "," - << field_to_string(row.alu_div_u16_r6) << "," << field_to_string(row.alu_div_u16_r7) << "," - << field_to_string(row.alu_divisor_hi) << "," << field_to_string(row.alu_divisor_lo) << "," - << field_to_string(row.alu_ff_tag) << "," << field_to_string(row.alu_ia) << "," - << field_to_string(row.alu_ib) << "," << field_to_string(row.alu_ic) << "," - << field_to_string(row.alu_in_tag) << "," << field_to_string(row.alu_op_add) << "," + << field_to_string(row.kernel_kernel_inputs) << "," << field_to_string(row.kernel_kernel_value_out) << "," + << field_to_string(row.kernel_kernel_side_effect_out) << "," + << field_to_string(row.kernel_kernel_metadata_out) << "," << field_to_string(row.alu_a_hi) << "," + << field_to_string(row.alu_a_lo) << "," << field_to_string(row.alu_b_hi) << "," + << field_to_string(row.alu_b_lo) << "," << field_to_string(row.alu_borrow) << "," + << field_to_string(row.alu_cf) << "," << field_to_string(row.alu_clk) << "," + << field_to_string(row.alu_cmp_rng_ctr) << "," << field_to_string(row.alu_div_u16_r0) << "," + << field_to_string(row.alu_div_u16_r1) << "," << field_to_string(row.alu_div_u16_r2) << "," + << field_to_string(row.alu_div_u16_r3) << "," << field_to_string(row.alu_div_u16_r4) << "," + << field_to_string(row.alu_div_u16_r5) << "," << field_to_string(row.alu_div_u16_r6) << "," + << field_to_string(row.alu_div_u16_r7) << "," << field_to_string(row.alu_divisor_hi) << "," + << field_to_string(row.alu_divisor_lo) << "," << field_to_string(row.alu_ff_tag) << "," + << field_to_string(row.alu_ia) << "," << field_to_string(row.alu_ib) << "," << field_to_string(row.alu_ic) + << "," << field_to_string(row.alu_in_tag) << "," << field_to_string(row.alu_op_add) << "," << field_to_string(row.alu_op_cast) << "," << field_to_string(row.alu_op_cast_prev) << "," << field_to_string(row.alu_op_div) << "," << field_to_string(row.alu_op_div_a_lt_b) << "," << field_to_string(row.alu_op_div_std) << "," << field_to_string(row.alu_op_eq) << "," @@ -473,11 +475,8 @@ template std::ostream& operator<<(std::ostream& os, AvmFullRow << field_to_string(row.kernel_emit_note_hash_write_offset) << "," << field_to_string(row.kernel_emit_nullifier_write_offset) << "," << field_to_string(row.kernel_emit_unencrypted_log_write_offset) << "," - << field_to_string(row.kernel_kernel_in_offset) << "," << field_to_string(row.kernel_kernel_inputs) << "," - << field_to_string(row.kernel_kernel_metadata_out) << "," << field_to_string(row.kernel_kernel_out_offset) - << "," << field_to_string(row.kernel_kernel_side_effect_out) << "," - << field_to_string(row.kernel_kernel_value_out) << "," - << field_to_string(row.kernel_l1_to_l2_msg_exists_write_offset) << "," + << field_to_string(row.kernel_kernel_in_offset) << "," << field_to_string(row.kernel_kernel_out_offset) + << "," << field_to_string(row.kernel_l1_to_l2_msg_exists_write_offset) << "," << field_to_string(row.kernel_note_hash_exist_write_offset) << "," << field_to_string(row.kernel_nullifier_exists_write_offset) << "," << field_to_string(row.kernel_nullifier_non_exists_write_offset) << "," diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp index 83e3cd74b16..b8f8a107901 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp @@ -87,6 +87,10 @@ namespace bb { template struct AvmFullRow { FF main_clk{}; FF main_sel_first{}; + FF kernel_kernel_inputs{}; + FF kernel_kernel_value_out{}; + FF kernel_kernel_side_effect_out{}; + FF kernel_kernel_metadata_out{}; FF alu_a_hi{}; FF alu_a_lo{}; FF alu_b_hi{}; @@ -207,11 +211,7 @@ template struct AvmFullRow { FF kernel_emit_nullifier_write_offset{}; FF kernel_emit_unencrypted_log_write_offset{}; FF kernel_kernel_in_offset{}; - FF kernel_kernel_inputs{}; - FF kernel_kernel_metadata_out{}; FF kernel_kernel_out_offset{}; - FF kernel_kernel_side_effect_out{}; - FF kernel_kernel_value_out{}; FF kernel_l1_to_l2_msg_exists_write_offset{}; FF kernel_note_hash_exist_write_offset{}; FF kernel_nullifier_exists_write_offset{}; @@ -570,6 +570,10 @@ class AvmCircuitBuilder { for (size_t i = 0; i < rows.size(); i++) { polys.main_clk[i] = rows[i].main_clk; polys.main_sel_first[i] = rows[i].main_sel_first; + polys.kernel_kernel_inputs[i] = rows[i].kernel_kernel_inputs; + polys.kernel_kernel_value_out[i] = rows[i].kernel_kernel_value_out; + polys.kernel_kernel_side_effect_out[i] = rows[i].kernel_kernel_side_effect_out; + polys.kernel_kernel_metadata_out[i] = rows[i].kernel_kernel_metadata_out; polys.alu_a_hi[i] = rows[i].alu_a_hi; polys.alu_a_lo[i] = rows[i].alu_a_lo; polys.alu_b_hi[i] = rows[i].alu_b_hi; @@ -690,11 +694,7 @@ class AvmCircuitBuilder { polys.kernel_emit_nullifier_write_offset[i] = rows[i].kernel_emit_nullifier_write_offset; polys.kernel_emit_unencrypted_log_write_offset[i] = rows[i].kernel_emit_unencrypted_log_write_offset; polys.kernel_kernel_in_offset[i] = rows[i].kernel_kernel_in_offset; - polys.kernel_kernel_inputs[i] = rows[i].kernel_kernel_inputs; - polys.kernel_kernel_metadata_out[i] = rows[i].kernel_kernel_metadata_out; polys.kernel_kernel_out_offset[i] = rows[i].kernel_kernel_out_offset; - polys.kernel_kernel_side_effect_out[i] = rows[i].kernel_kernel_side_effect_out; - polys.kernel_kernel_value_out[i] = rows[i].kernel_kernel_value_out; polys.kernel_l1_to_l2_msg_exists_write_offset[i] = rows[i].kernel_l1_to_l2_msg_exists_write_offset; polys.kernel_note_hash_exist_write_offset[i] = rows[i].kernel_note_hash_exist_write_offset; polys.kernel_nullifier_exists_write_offset[i] = rows[i].kernel_nullifier_exists_write_offset; diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp index 41cae773d42..283812ece0f 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp @@ -256,6 +256,10 @@ class AvmFlavor { template class WitnessEntities { public: DEFINE_FLAVOR_MEMBERS(DataType, + kernel_kernel_inputs, + kernel_kernel_value_out, + kernel_kernel_side_effect_out, + kernel_kernel_metadata_out, alu_a_hi, alu_a_lo, alu_b_hi, @@ -376,11 +380,7 @@ class AvmFlavor { kernel_emit_nullifier_write_offset, kernel_emit_unencrypted_log_write_offset, kernel_kernel_in_offset, - kernel_kernel_inputs, - kernel_kernel_metadata_out, kernel_kernel_out_offset, - kernel_kernel_side_effect_out, - kernel_kernel_value_out, kernel_l1_to_l2_msg_exists_write_offset, kernel_note_hash_exist_write_offset, kernel_nullifier_exists_write_offset, @@ -642,7 +642,11 @@ class AvmFlavor { RefVector get_wires() { - return { alu_a_hi, + return { kernel_kernel_inputs, + kernel_kernel_value_out, + kernel_kernel_side_effect_out, + kernel_kernel_metadata_out, + alu_a_hi, alu_a_lo, alu_b_hi, alu_b_lo, @@ -762,11 +766,7 @@ class AvmFlavor { kernel_emit_nullifier_write_offset, kernel_emit_unencrypted_log_write_offset, kernel_kernel_in_offset, - kernel_kernel_inputs, - kernel_kernel_metadata_out, kernel_kernel_out_offset, - kernel_kernel_side_effect_out, - kernel_kernel_value_out, kernel_l1_to_l2_msg_exists_write_offset, kernel_note_hash_exist_write_offset, kernel_nullifier_exists_write_offset, @@ -1033,6 +1033,10 @@ class AvmFlavor { DEFINE_FLAVOR_MEMBERS(DataType, main_clk, main_sel_first, + kernel_kernel_inputs, + kernel_kernel_value_out, + kernel_kernel_side_effect_out, + kernel_kernel_metadata_out, alu_a_hi, alu_a_lo, alu_b_hi, @@ -1153,11 +1157,7 @@ class AvmFlavor { kernel_emit_nullifier_write_offset, kernel_emit_unencrypted_log_write_offset, kernel_kernel_in_offset, - kernel_kernel_inputs, - kernel_kernel_metadata_out, kernel_kernel_out_offset, - kernel_kernel_side_effect_out, - kernel_kernel_value_out, kernel_l1_to_l2_msg_exists_write_offset, kernel_note_hash_exist_write_offset, kernel_nullifier_exists_write_offset, @@ -1486,6 +1486,10 @@ class AvmFlavor { { return { main_clk, main_sel_first, + kernel_kernel_inputs, + kernel_kernel_value_out, + kernel_kernel_side_effect_out, + kernel_kernel_metadata_out, alu_a_hi, alu_a_lo, alu_b_hi, @@ -1606,11 +1610,7 @@ class AvmFlavor { kernel_emit_nullifier_write_offset, kernel_emit_unencrypted_log_write_offset, kernel_kernel_in_offset, - kernel_kernel_inputs, - kernel_kernel_metadata_out, kernel_kernel_out_offset, - kernel_kernel_side_effect_out, - kernel_kernel_value_out, kernel_l1_to_l2_msg_exists_write_offset, kernel_note_hash_exist_write_offset, kernel_nullifier_exists_write_offset, @@ -1939,6 +1939,10 @@ class AvmFlavor { { return { main_clk, main_sel_first, + kernel_kernel_inputs, + kernel_kernel_value_out, + kernel_kernel_side_effect_out, + kernel_kernel_metadata_out, alu_a_hi, alu_a_lo, alu_b_hi, @@ -2059,11 +2063,7 @@ class AvmFlavor { kernel_emit_nullifier_write_offset, kernel_emit_unencrypted_log_write_offset, kernel_kernel_in_offset, - kernel_kernel_inputs, - kernel_kernel_metadata_out, kernel_kernel_out_offset, - kernel_kernel_side_effect_out, - kernel_kernel_value_out, kernel_l1_to_l2_msg_exists_write_offset, kernel_note_hash_exist_write_offset, kernel_nullifier_exists_write_offset, @@ -2686,7 +2686,7 @@ class AvmFlavor { } } - [[nodiscard]] size_t get_polynomial_size() const { return alu_a_hi.size(); } + [[nodiscard]] size_t get_polynomial_size() const { return kernel_kernel_inputs.size(); } /** * @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which * represents one row in the execution trace. @@ -2748,6 +2748,10 @@ class AvmFlavor { { Base::main_clk = "MAIN_CLK"; Base::main_sel_first = "MAIN_SEL_FIRST"; + Base::kernel_kernel_inputs = "KERNEL_KERNEL_INPUTS"; + Base::kernel_kernel_value_out = "KERNEL_KERNEL_VALUE_OUT"; + Base::kernel_kernel_side_effect_out = "KERNEL_KERNEL_SIDE_EFFECT_OUT"; + Base::kernel_kernel_metadata_out = "KERNEL_KERNEL_METADATA_OUT"; Base::alu_a_hi = "ALU_A_HI"; Base::alu_a_lo = "ALU_A_LO"; Base::alu_b_hi = "ALU_B_HI"; @@ -2868,11 +2872,7 @@ class AvmFlavor { Base::kernel_emit_nullifier_write_offset = "KERNEL_EMIT_NULLIFIER_WRITE_OFFSET"; Base::kernel_emit_unencrypted_log_write_offset = "KERNEL_EMIT_UNENCRYPTED_LOG_WRITE_OFFSET"; Base::kernel_kernel_in_offset = "KERNEL_KERNEL_IN_OFFSET"; - Base::kernel_kernel_inputs = "KERNEL_KERNEL_INPUTS"; - Base::kernel_kernel_metadata_out = "KERNEL_KERNEL_METADATA_OUT"; Base::kernel_kernel_out_offset = "KERNEL_KERNEL_OUT_OFFSET"; - Base::kernel_kernel_side_effect_out = "KERNEL_KERNEL_SIDE_EFFECT_OUT"; - Base::kernel_kernel_value_out = "KERNEL_KERNEL_VALUE_OUT"; Base::kernel_l1_to_l2_msg_exists_write_offset = "KERNEL_L1_TO_L2_MSG_EXISTS_WRITE_OFFSET"; Base::kernel_note_hash_exist_write_offset = "KERNEL_NOTE_HASH_EXIST_WRITE_OFFSET"; Base::kernel_nullifier_exists_write_offset = "KERNEL_NULLIFIER_EXISTS_WRITE_OFFSET"; @@ -3150,6 +3150,10 @@ class AvmFlavor { public: uint32_t circuit_size; + Commitment kernel_kernel_inputs; + Commitment kernel_kernel_value_out; + Commitment kernel_kernel_side_effect_out; + Commitment kernel_kernel_metadata_out; Commitment alu_a_hi; Commitment alu_a_lo; Commitment alu_b_hi; @@ -3270,11 +3274,7 @@ class AvmFlavor { Commitment kernel_emit_nullifier_write_offset; Commitment kernel_emit_unencrypted_log_write_offset; Commitment kernel_kernel_in_offset; - Commitment kernel_kernel_inputs; - Commitment kernel_kernel_metadata_out; Commitment kernel_kernel_out_offset; - Commitment kernel_kernel_side_effect_out; - Commitment kernel_kernel_value_out; Commitment kernel_l1_to_l2_msg_exists_write_offset; Commitment kernel_note_hash_exist_write_offset; Commitment kernel_nullifier_exists_write_offset; @@ -3552,6 +3552,10 @@ class AvmFlavor { circuit_size = deserialize_from_buffer(proof_data, num_frs_read); size_t log_n = numeric::get_msb(circuit_size); + kernel_kernel_inputs = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_kernel_value_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_kernel_side_effect_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); + kernel_kernel_metadata_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); alu_a_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); alu_a_lo = deserialize_from_buffer(Transcript::proof_data, num_frs_read); alu_b_hi = deserialize_from_buffer(Transcript::proof_data, num_frs_read); @@ -3676,11 +3680,7 @@ class AvmFlavor { kernel_emit_unencrypted_log_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); kernel_kernel_in_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - kernel_kernel_inputs = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - kernel_kernel_metadata_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); kernel_kernel_out_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - kernel_kernel_side_effect_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); - kernel_kernel_value_out = deserialize_from_buffer(Transcript::proof_data, num_frs_read); kernel_l1_to_l2_msg_exists_write_offset = deserialize_from_buffer(Transcript::proof_data, num_frs_read); kernel_note_hash_exist_write_offset = @@ -3970,6 +3970,10 @@ class AvmFlavor { serialize_to_buffer(circuit_size, Transcript::proof_data); + serialize_to_buffer(kernel_kernel_inputs, Transcript::proof_data); + serialize_to_buffer(kernel_kernel_value_out, Transcript::proof_data); + serialize_to_buffer(kernel_kernel_side_effect_out, Transcript::proof_data); + serialize_to_buffer(kernel_kernel_metadata_out, Transcript::proof_data); serialize_to_buffer(alu_a_hi, Transcript::proof_data); serialize_to_buffer(alu_a_lo, Transcript::proof_data); serialize_to_buffer(alu_b_hi, Transcript::proof_data); @@ -4090,11 +4094,7 @@ class AvmFlavor { serialize_to_buffer(kernel_emit_nullifier_write_offset, Transcript::proof_data); serialize_to_buffer(kernel_emit_unencrypted_log_write_offset, Transcript::proof_data); serialize_to_buffer(kernel_kernel_in_offset, Transcript::proof_data); - serialize_to_buffer(kernel_kernel_inputs, Transcript::proof_data); - serialize_to_buffer(kernel_kernel_metadata_out, Transcript::proof_data); serialize_to_buffer(kernel_kernel_out_offset, Transcript::proof_data); - serialize_to_buffer(kernel_kernel_side_effect_out, Transcript::proof_data); - serialize_to_buffer(kernel_kernel_value_out, Transcript::proof_data); serialize_to_buffer(kernel_l1_to_l2_msg_exists_write_offset, Transcript::proof_data); serialize_to_buffer(kernel_note_hash_exist_write_offset, Transcript::proof_data); serialize_to_buffer(kernel_nullifier_exists_write_offset, Transcript::proof_data); diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp index 2bdb385ef3f..c6a7622629b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_prover.cpp @@ -59,6 +59,10 @@ void AvmProver::execute_wire_commitments_round() // Commit to all polynomials (apart from logderivative inverse polynomials, which are committed to in the later // logderivative phase) + witness_commitments.kernel_kernel_inputs = commitment_key->commit(key->kernel_kernel_inputs); + witness_commitments.kernel_kernel_value_out = commitment_key->commit(key->kernel_kernel_value_out); + witness_commitments.kernel_kernel_side_effect_out = commitment_key->commit(key->kernel_kernel_side_effect_out); + witness_commitments.kernel_kernel_metadata_out = commitment_key->commit(key->kernel_kernel_metadata_out); witness_commitments.alu_a_hi = commitment_key->commit(key->alu_a_hi); witness_commitments.alu_a_lo = commitment_key->commit(key->alu_a_lo); witness_commitments.alu_b_hi = commitment_key->commit(key->alu_b_hi); @@ -183,11 +187,7 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.kernel_emit_unencrypted_log_write_offset = commitment_key->commit(key->kernel_emit_unencrypted_log_write_offset); witness_commitments.kernel_kernel_in_offset = commitment_key->commit(key->kernel_kernel_in_offset); - witness_commitments.kernel_kernel_inputs = commitment_key->commit(key->kernel_kernel_inputs); - witness_commitments.kernel_kernel_metadata_out = commitment_key->commit(key->kernel_kernel_metadata_out); witness_commitments.kernel_kernel_out_offset = commitment_key->commit(key->kernel_kernel_out_offset); - witness_commitments.kernel_kernel_side_effect_out = commitment_key->commit(key->kernel_kernel_side_effect_out); - witness_commitments.kernel_kernel_value_out = commitment_key->commit(key->kernel_kernel_value_out); witness_commitments.kernel_l1_to_l2_msg_exists_write_offset = commitment_key->commit(key->kernel_l1_to_l2_msg_exists_write_offset); witness_commitments.kernel_note_hash_exist_write_offset = @@ -402,6 +402,13 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.lookup_div_u16_7_counts = commitment_key->commit(key->lookup_div_u16_7_counts); // Send all commitments to the verifier + transcript->send_to_verifier(commitment_labels.kernel_kernel_inputs, witness_commitments.kernel_kernel_inputs); + transcript->send_to_verifier(commitment_labels.kernel_kernel_value_out, + witness_commitments.kernel_kernel_value_out); + transcript->send_to_verifier(commitment_labels.kernel_kernel_side_effect_out, + witness_commitments.kernel_kernel_side_effect_out); + transcript->send_to_verifier(commitment_labels.kernel_kernel_metadata_out, + witness_commitments.kernel_kernel_metadata_out); transcript->send_to_verifier(commitment_labels.alu_a_hi, witness_commitments.alu_a_hi); transcript->send_to_verifier(commitment_labels.alu_a_lo, witness_commitments.alu_a_lo); transcript->send_to_verifier(commitment_labels.alu_b_hi, witness_commitments.alu_b_hi); @@ -535,15 +542,8 @@ void AvmProver::execute_wire_commitments_round() witness_commitments.kernel_emit_unencrypted_log_write_offset); transcript->send_to_verifier(commitment_labels.kernel_kernel_in_offset, witness_commitments.kernel_kernel_in_offset); - transcript->send_to_verifier(commitment_labels.kernel_kernel_inputs, witness_commitments.kernel_kernel_inputs); - transcript->send_to_verifier(commitment_labels.kernel_kernel_metadata_out, - witness_commitments.kernel_kernel_metadata_out); transcript->send_to_verifier(commitment_labels.kernel_kernel_out_offset, witness_commitments.kernel_kernel_out_offset); - transcript->send_to_verifier(commitment_labels.kernel_kernel_side_effect_out, - witness_commitments.kernel_kernel_side_effect_out); - transcript->send_to_verifier(commitment_labels.kernel_kernel_value_out, - witness_commitments.kernel_kernel_value_out); transcript->send_to_verifier(commitment_labels.kernel_l1_to_l2_msg_exists_write_offset, witness_commitments.kernel_l1_to_l2_msg_exists_write_offset); transcript->send_to_verifier(commitment_labels.kernel_note_hash_exist_write_offset, diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp index 32cb192f93a..24a8b6c6f0b 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_verifier.cpp @@ -70,6 +70,14 @@ bool AvmVerifier::verify_proof(const HonkProof& proof, const std::vectortemplate receive_from_prover(commitment_labels.kernel_kernel_inputs); + commitments.kernel_kernel_value_out = + transcript->template receive_from_prover(commitment_labels.kernel_kernel_value_out); + commitments.kernel_kernel_side_effect_out = + transcript->template receive_from_prover(commitment_labels.kernel_kernel_side_effect_out); + commitments.kernel_kernel_metadata_out = + transcript->template receive_from_prover(commitment_labels.kernel_kernel_metadata_out); commitments.alu_a_hi = transcript->template receive_from_prover(commitment_labels.alu_a_hi); commitments.alu_a_lo = transcript->template receive_from_prover(commitment_labels.alu_a_lo); commitments.alu_b_hi = transcript->template receive_from_prover(commitment_labels.alu_b_hi); @@ -233,16 +241,8 @@ bool AvmVerifier::verify_proof(const HonkProof& proof, const std::vectortemplate receive_from_prover(commitment_labels.kernel_kernel_in_offset); - commitments.kernel_kernel_inputs = - transcript->template receive_from_prover(commitment_labels.kernel_kernel_inputs); - commitments.kernel_kernel_metadata_out = - transcript->template receive_from_prover(commitment_labels.kernel_kernel_metadata_out); commitments.kernel_kernel_out_offset = transcript->template receive_from_prover(commitment_labels.kernel_kernel_out_offset); - commitments.kernel_kernel_side_effect_out = - transcript->template receive_from_prover(commitment_labels.kernel_kernel_side_effect_out); - commitments.kernel_kernel_value_out = - transcript->template receive_from_prover(commitment_labels.kernel_kernel_value_out); commitments.kernel_l1_to_l2_msg_exists_write_offset = transcript->template receive_from_prover(commitment_labels.kernel_l1_to_l2_msg_exists_write_offset); commitments.kernel_note_hash_exist_write_offset = diff --git a/bb-pilcom/.gitignore b/bb-pilcom/.gitignore new file mode 100644 index 00000000000..41bfb440101 --- /dev/null +++ b/bb-pilcom/.gitignore @@ -0,0 +1 @@ +**/target/* \ No newline at end of file diff --git a/bb-pilcom/Cargo.lock b/bb-pilcom/Cargo.lock new file mode 100644 index 00000000000..d1179b177b9 --- /dev/null +++ b/bb-pilcom/Cargo.lock @@ -0,0 +1,1880 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anstream" +version = "0.6.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" + +[[package]] +name = "anstyle-parse" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "ark-bn254" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a22f4561524cd949590d78d7d4c5df8f592430d221f7f3c9497bbafd8972120f" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-ec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", + "itertools 0.10.5", + "num-traits", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest", + "itertools 0.10.5", + "num-bigint", + "num-traits", + "paste", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand", +] + +[[package]] +name = "ascii-canvas" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8824ecca2e851cec16968d54a01dd372ef8f95b244fb84b84e70128be347c3c6" +dependencies = [ + "term", +] + +[[package]] +name = "auto_enums" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1899bfcfd9340ceea3533ea157360ba8fa864354eccbceab58e1006ecab35393" +dependencies = [ + "derive_utils", + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bb-pil-backend" +version = "0.1.0" +dependencies = [ + "itertools 0.10.5", + "log", + "num-bigint", + "num-integer", + "num-traits", + "powdr-ast", + "powdr-number", + "rand", +] + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "serde", + "windows-targets", +] + +[[package]] +name = "clap" +version = "4.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "clap_lex" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" + +[[package]] +name = "cli" +version = "0.1.0" +dependencies = [ + "bb-pil-backend", + "clap", + "itertools 0.10.5", + "log", + "num-bigint", + "num-integer", + "num-traits", + "powdr-ast", + "powdr-number", + "powdr-pil-analyzer", + "rand", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "colorchoice" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "csv" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" +dependencies = [ + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" +dependencies = [ + "memchr", +] + +[[package]] +name = "darling" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622687fe0bac72a04e5599029151f5796111b90f1baaa9b544d807a5e31cd120" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.66", +] + +[[package]] +name = "darling_macro" +version = "0.20.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", + "serde", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive_more" +version = "0.99.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f33878137e4dafd7fa914ad4e259e18a4e8e532b9617a2d0150262bf53abfce" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.66", +] + +[[package]] +name = "derive_utils" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61bb5a1014ce6dfc2a378578509abe775a5aa06bff584a547555d9efdb81b926" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "crypto-common", +] + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "either" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" + +[[package]] +name = "ena" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d248bdd43ce613d87415282f69b9bb99d947d290b10962dd6c56233312c2ad5" +dependencies = [ + "log", +] + +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", +] + +[[package]] +name = "env_logger" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" +dependencies = [ + "humantime", + "is-terminal", + "log", + "regex", + "termcolor", +] + +[[package]] +name = "env_logger" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "log", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "half" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "humantime" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ibig" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1fcc7f316b2c079dde77564a1360639c1a956a23fa96122732e416cb10717bb" +dependencies = [ + "cfg-if", + "num-traits", + "rand", + "serde", + "static_assertions", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown 0.14.5", + "serde", +] + +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itertools" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lalrpop" +version = "0.19.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a1cbf952127589f2851ab2046af368fd20645491bb4b376f04b7f94d7a9837b" +dependencies = [ + "ascii-canvas", + "bit-set", + "diff", + "ena", + "is-terminal", + "itertools 0.10.5", + "lalrpop-util", + "petgraph", + "regex", + "regex-syntax 0.6.29", + "string_cache", + "term", + "tiny-keccak", + "unicode-xid", +] + +[[package]] +name = "lalrpop-util" +version = "0.19.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3c48237b9604c5a4702de6b824e02006c3214327564636aef27c1028a8fa0ed" +dependencies = [ + "regex", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num-bigint" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" +dependencies = [ + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "petgraph" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" +dependencies = [ + "fixedbitset", + "indexmap 2.2.6", +] + +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "powdr-ast" +version = "0.0.1" +dependencies = [ + "auto_enums", + "derive_more", + "itertools 0.11.0", + "num-traits", + "powdr-number", + "powdr-parser", + "powdr-parser-util", + "powdr-pil-analyzer", + "pretty_assertions", + "schemars", + "serde", + "serde_cbor", + "test-log", +] + +[[package]] +name = "powdr-number" +version = "0.0.1" +dependencies = [ + "ark-bn254", + "ark-ff", + "ark-serialize", + "csv", + "env_logger 0.10.2", + "ibig", + "num-bigint", + "num-traits", + "schemars", + "serde", + "serde_with", + "test-log", +] + +[[package]] +name = "powdr-parser" +version = "0.0.1" +dependencies = [ + "derive_more", + "env_logger 0.10.2", + "lalrpop", + "lalrpop-util", + "lazy_static", + "num-traits", + "powdr-ast", + "powdr-number", + "powdr-parser-util", + "pretty_assertions", + "similar", + "test-log", + "walkdir", +] + +[[package]] +name = "powdr-parser-util" +version = "0.0.1" +dependencies = [ + "codespan-reporting", + "env_logger 0.10.2", + "lalrpop-util", + "schemars", + "serde", + "test-log", +] + +[[package]] +name = "powdr-pil-analyzer" +version = "0.0.1" +dependencies = [ + "env_logger 0.10.2", + "itertools 0.10.5", + "lazy_static", + "num-traits", + "powdr-ast", + "powdr-number", + "powdr-parser", + "powdr-parser-util", + "pretty_assertions", + "test-log", +] + +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "pretty_assertions" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af7cee1a6c8a5b9208b3cb1061f10c0cb689087b3d8ce85fb9d2dd7a29b6ba66" +dependencies = [ + "diff", + "yansi", +] + +[[package]] +name = "proc-macro2" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "redox_syscall" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustversion" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schemars" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" +dependencies = [ + "dyn-clone", + "indexmap 1.9.3", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.66", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + +[[package]] +name = "serde" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_cbor" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" +dependencies = [ + "half", + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "serde_json" +version = "1.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_with" +version = "3.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ad483d2ab0149d5a5ebcd9972a3852711e0153d863bf5a5d0391d28883c4a20" +dependencies = [ + "base64", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.2.6", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65569b702f41443e8bc8bbb1c5779bd0450bbe723b56198980e80ec45780bce2" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "similar" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" + +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared", + "precomputed-hash", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "test-log" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dffced63c2b5c7be278154d76b479f9f9920ed34e7574201407f0b14e2bbb93" +dependencies = [ + "env_logger 0.11.3", + "test-log-macros", + "tracing-subscriber", +] + +[[package]] +name = "test-log-macros" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5999e24eaa32083191ba4e425deb75cdf25efefabe5aaccb7446dd0d4122a3f5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "thiserror" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-width" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.66", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + +[[package]] +name = "zerocopy" +version = "0.7.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] diff --git a/bb-pilcom/Cargo.toml b/bb-pilcom/Cargo.toml new file mode 100644 index 00000000000..5df0e982d9d --- /dev/null +++ b/bb-pilcom/Cargo.toml @@ -0,0 +1,28 @@ +[workspace] +resolver = "2" +members = [ + "cli", + "bb-pil-backend", + "powdr/ast", + "powdr/number", + "powdr/parser", + "powdr/parser-util", + "powdr/pil-analyzer" +] + +[workspace.package] +version = "0.0.1" +edition = "2021" +license = "MIT" +homepage = "https://powdr.org" +repository = "https://github.com/powdr-labs/powdr" + + +[workspace.dependencies] +bb-pil-backend = { path = "./bb-pil-backend" } +cli = { path = "./cli" } +powdr-ast = { path = "./powdr/ast" } +powdr-number = { path = "./powdr/number" } +powdr-parser = { path = "./powdr/parser" } +powdr-parser-util = { path = "./powdr/parser-util" } +powdr-pil-analyzer = { path = "./powdr/pil-analyzer" } diff --git a/bb-pilcom/bb-pil-backend/Cargo.toml b/bb-pilcom/bb-pil-backend/Cargo.toml new file mode 100644 index 00000000000..0904cd7f445 --- /dev/null +++ b/bb-pilcom/bb-pil-backend/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "bb-pil-backend" +version = "0.1.0" +authors = ["Aztec Labs"] +edition = "2021" + +[dependencies] +num-bigint = "0.4.3" + +powdr-number = { path = "../powdr/number" } +num-traits = "0.2.15" +num-integer = "0.1.45" +itertools = "^0.10" +log = "0.4.17" +rand = "0.8.5" +powdr-ast = { path = "../powdr/ast" } diff --git a/bb-pilcom/bb-pil-backend/src/circuit_builder.rs b/bb-pilcom/bb-pil-backend/src/circuit_builder.rs new file mode 100644 index 00000000000..1f93f0367e8 --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/circuit_builder.rs @@ -0,0 +1,374 @@ +use crate::{ + file_writer::BBFiles, + relation_builder::create_row_type, + utils::{get_relations_imports, map_with_newline, snake_case}, +}; + +pub trait CircuitBuilder { + fn create_circuit_builder_hpp( + &mut self, + name: &str, + relations: &[String], + permutations: &[String], + all_cols_without_inverses: &[String], + all_cols: &[String], + to_be_shifted: &[String], + all_cols_with_shifts: &[String], + ); + + fn create_circuit_builder_cpp(&mut self, name: &str, all_cols: &[String]); +} + +fn circuit_hpp_includes(name: &str, relations: &[String], permutations: &[String]) -> String { + let relation_imports = get_relations_imports(name, relations, permutations); + format!( + " + // AUTOGENERATED FILE + #pragma once + + #include +#ifndef __wasm__ + #include +#endif + + #include \"barretenberg/common/constexpr_utils.hpp\" + #include \"barretenberg/common/throw_or_abort.hpp\" + #include \"barretenberg/ecc/curves/bn254/fr.hpp\" + #include \"barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp\" + #include \"barretenberg/relations/generic_permutation/generic_permutation_relation.hpp\" + #include \"barretenberg/relations/generic_lookup/generic_lookup_relation.hpp\" + #include \"barretenberg/honk/proof_system/logderivative_library.hpp\" + + #include \"barretenberg/vm/generated/{name}_flavor.hpp\" + {relation_imports} +" + ) +} + +fn get_params() -> &'static str { + r#" + const FF gamma = FF::random_element(); + const FF beta = FF::random_element(); + bb::RelationParameters params{ + .eta = 0, + .beta = beta, + .gamma = gamma, + .public_input_delta = 0, + .lookup_grand_product_delta = 0, + .beta_sqr = 0, + .beta_cube = 0, + .eccvm_set_permutation_delta = 0, + }; + "# +} + +impl CircuitBuilder for BBFiles { + // Create circuit builder + // Generate some code that can read a commits.bin and constants.bin into data structures that bberg understands + fn create_circuit_builder_hpp( + &mut self, + name: &str, + relations: &[String], + permutations: &[String], + all_cols_without_inverses: &[String], + all_cols: &[String], + to_be_shifted: &[String], + all_cols_with_shifts: &[String], + ) { + let includes = circuit_hpp_includes(&snake_case(name), relations, permutations); + + let row_with_all_included = create_row_type(&format!("{name}Full"), all_cols_with_shifts); + + let num_polys = all_cols.len(); + let num_cols = all_cols.len() + to_be_shifted.len(); + + // Declare mapping transformations + let compute_polys_transformation = + |name: &String| format!("polys.{name}[i] = rows[i].{name};"); + let all_polys_transformation = + |name: &String| format!("polys.{name}_shift = Polynomial(polys.{name}.shifted());"); + let check_circuit_transformation = |relation_name: &String| { + format!( + "auto {relation_name} = [=]() {{ + return evaluate_relation.template operator()<{name}_vm::{relation_name}>(\"{relation_name}\", {name}_vm::get_relation_label_{relation_name}); + }}; + ", + name = name, + relation_name = relation_name + ) + }; + let check_lookup_transformation = |lookup_name: &String| { + let lookup_name_upper = lookup_name.to_uppercase(); + format!( + "auto {lookup_name} = [=]() {{ + return evaluate_logderivative.template operator()<{lookup_name}_relation>(\"{lookup_name_upper}\"); + }}; + " + ) + }; + + // When we are running natively, we want check circuit to run as futures; however, futures are not supported in wasm, so we must provide an + // alternative codepath that will execute the closures in serial + let emplace_future_transformation = |relation_name: &String| { + format!( + " + relation_futures.emplace_back(std::async(std::launch::async, {relation_name})); + " + ) + }; + + let execute_serial_transformation = |relation_name: &String| { + format!( + " + {relation_name}(); + " + ) + }; + + // Apply transformations + let compute_polys_assignemnt = + map_with_newline(all_cols_without_inverses, compute_polys_transformation); + let all_poly_shifts = map_with_newline(to_be_shifted, all_polys_transformation); + let check_circuit_for_each_relation = + map_with_newline(relations, check_circuit_transformation); + let check_circuit_for_each_lookup = + map_with_newline(permutations, check_lookup_transformation); + + // With futures + let emplace_future_relations = map_with_newline(relations, emplace_future_transformation); + let emplace_future_lookups = map_with_newline(permutations, emplace_future_transformation); + + // With threads + let serial_relations = map_with_newline(relations, execute_serial_transformation); + let serial_lookups = map_with_newline(permutations, execute_serial_transformation); + + let (params, lookup_check_closure) = if !permutations.is_empty() { + (get_params(), get_lookup_check_closure()) + } else { + ("", "".to_owned()) + }; + let relation_check_closure = if !relations.is_empty() { + get_relation_check_closure() + } else { + "".to_owned() + }; + + let circuit_hpp = format!(" +{includes} + +namespace bb {{ + +{row_with_all_included}; + +template std::ostream& operator<<(std::ostream& os, {name}FullRow const& row); + +class {name}CircuitBuilder {{ + public: + using Flavor = bb::{name}Flavor; + using FF = Flavor::FF; + using Row = {name}FullRow; + + // TODO: template + using Polynomial = Flavor::Polynomial; + using ProverPolynomials = Flavor::ProverPolynomials; + + static constexpr size_t num_fixed_columns = {num_cols}; + static constexpr size_t num_polys = {num_polys}; + std::vector rows; + + void set_trace(std::vector&& trace) {{ rows = std::move(trace); }} + + ProverPolynomials compute_polynomials() {{ + const auto num_rows = get_circuit_subgroup_size(); + ProverPolynomials polys; + + // Allocate mem for each column + for (auto& poly : polys.get_all()) {{ + poly = Polynomial(num_rows); + }} + + for (size_t i = 0; i < rows.size(); i++) {{ + {compute_polys_assignemnt} + }} + + {all_poly_shifts } + + return polys; + }} + + [[maybe_unused]] bool check_circuit() + {{ + {params} + + auto polys = compute_polynomials(); + const size_t num_rows = polys.get_polynomial_size(); + + {relation_check_closure} + + {lookup_check_closure} + + {check_circuit_for_each_relation} + + {check_circuit_for_each_lookup} + +#ifndef __wasm__ + + // Evaluate check circuit closures as futures + std::vector> relation_futures; + + {emplace_future_relations} + {emplace_future_lookups} + + + // Wait for lookup evaluations to complete + for (auto& future : relation_futures) {{ + int result = future.get(); + if (!result) {{ + return false; + }} + }} +#else + {serial_relations} + {serial_lookups} + +#endif + + return true; + }} + + + [[nodiscard]] size_t get_num_gates() const {{ return rows.size(); }} + + [[nodiscard]] size_t get_circuit_subgroup_size() const + {{ + const size_t num_rows = get_num_gates(); + const auto num_rows_log2 = static_cast(numeric::get_msb64(num_rows)); + size_t num_rows_pow2 = 1UL << (num_rows_log2 + (1UL << num_rows_log2 == num_rows ? 0 : 1)); + return num_rows_pow2; + }} + + +}}; +}} + "); + + self.write_file( + &self.circuit, + &format!("{}_circuit_builder.hpp", snake_case(name)), + &circuit_hpp, + ); + } + + fn create_circuit_builder_cpp(&mut self, name: &str, all_cols: &[String]) { + let names_list = map_with_newline(all_cols, |name: &String| format!("\"{}\",", name)); + let stream_all_relations = map_with_newline(all_cols, |name: &String| { + format!("<< field_to_string(row.{}) << \",\"", name) + }); + let snake_name = snake_case(name); + + let circuit_cpp = format!( + " +#include \"barretenberg/vm/generated/{snake_name}_circuit_builder.hpp\" + +namespace bb {{ +namespace {{ + +template std::string field_to_string(const FF& ff) +{{ + std::ostringstream os; + os << ff; + std::string raw = os.str(); + auto first_not_zero = raw.find_first_not_of('0', 2); + std::string result = \"0x\" + (first_not_zero != std::string::npos ? raw.substr(first_not_zero) : \"0\"); + return result; +}} + +}} // namespace + +template std::vector {name}FullRow::names() {{ + return {{ + {names_list} + \"\" + }}; +}} + +template std::ostream& operator<<(std::ostream& os, {name}FullRow const& row) {{ + return os {stream_all_relations} + \"\"; +}} + +// Explicit template instantiation. +template std::ostream& operator<<(std::ostream& os, AvmFullRow const& row); +template std::vector AvmFullRow::names(); + +}} // namespace bb" + ); + + self.write_file( + &self.circuit, + &format!("{}_circuit_builder.cpp", snake_case(name)), + &circuit_cpp, + ); + } +} + +fn get_lookup_check_closure() -> String { + " + const auto evaluate_logderivative = [&](const std::string& lookup_name) { + + // Check the logderivative relation + bb::compute_logderivative_inverse< + Flavor, + LogDerivativeSettings>( + polys, params, num_rows); + + typename LogDerivativeSettings::SumcheckArrayOfValuesOverSubrelations + lookup_result; + + for (auto& r : lookup_result) { + r = 0; + } + for (size_t i = 0; i < num_rows; ++i) { + LogDerivativeSettings::accumulate(lookup_result, polys.get_row(i), params, 1); + } + for (auto r : lookup_result) { + if (r != 0) { + throw_or_abort(format(\"Lookup \", lookup_name, \" failed.\")); + return false; + } + } + return true; + }; + ".to_string() +} + +fn get_relation_check_closure() -> String { + " + const auto evaluate_relation = [&](const std::string& relation_name, + std::string (*debug_label)(int)) { + typename Relation::SumcheckArrayOfValuesOverSubrelations result; + for (auto& r : result) { + r = 0; + } + constexpr size_t NUM_SUBRELATIONS = result.size(); + + for (size_t i = 0; i < num_rows; ++i) { + Relation::accumulate(result, polys.get_row(i), {}, 1); + + bool x = true; + for (size_t j = 0; j < NUM_SUBRELATIONS; ++j) { + if (result[j] != 0) { + std::string row_name = debug_label(static_cast(j)); + throw_or_abort( + format(\"Relation \", relation_name, \", subrelation index \", row_name, \" failed at row \", i)); + x = false; + } + } + if (!x) { + return false; + } + } + return true; + }; + ".to_string() +} diff --git a/bb-pilcom/bb-pil-backend/src/composer_builder.rs b/bb-pilcom/bb-pil-backend/src/composer_builder.rs new file mode 100644 index 00000000000..2cbd8576d1a --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/composer_builder.rs @@ -0,0 +1,210 @@ +use crate::file_writer::BBFiles; +use crate::utils::snake_case; + +pub trait ComposerBuilder { + fn create_composer_cpp(&mut self, name: &str); + fn create_composer_hpp(&mut self, name: &str); +} + +impl ComposerBuilder for BBFiles { + fn create_composer_cpp(&mut self, name: &str) { + // Create a composer file, this is used to a prover and verifier for our flavour + let include_str = cpp_includes(&snake_case(name)); + + let composer_cpp = format!( + " +{include_str} + +namespace bb {{ + +using Flavor = {name}Flavor; +void {name}Composer::compute_witness(CircuitConstructor& circuit) +{{ + if (computed_witness) {{ + return; + }} + + auto polynomials = circuit.compute_polynomials(); + + for (auto [key_poly, prover_poly] : zip_view(proving_key->get_all(), polynomials.get_unshifted())) {{ + ASSERT(flavor_get_label(*proving_key, key_poly) == flavor_get_label(polynomials, prover_poly)); + key_poly = prover_poly; + }} + + computed_witness = true; +}} + +{name}Prover {name}Composer::create_prover(CircuitConstructor& circuit_constructor) +{{ + compute_proving_key(circuit_constructor); + compute_witness(circuit_constructor); + compute_commitment_key(circuit_constructor.get_circuit_subgroup_size()); + + {name}Prover output_state(proving_key, proving_key->commitment_key); + + return output_state; +}} + +{name}Verifier {name}Composer::create_verifier( + CircuitConstructor& circuit_constructor) +{{ + auto verification_key = compute_verification_key(circuit_constructor); + + {name}Verifier output_state(verification_key); + + auto pcs_verification_key = std::make_unique(); + + output_state.pcs_verification_key = std::move(pcs_verification_key); + + return output_state; +}} + +std::shared_ptr {name}Composer::compute_proving_key( + CircuitConstructor& circuit_constructor) +{{ + if (proving_key) {{ + return proving_key; + }} + + // Initialize proving_key + {{ + const size_t subgroup_size = circuit_constructor.get_circuit_subgroup_size(); + proving_key = std::make_shared(subgroup_size, 0); + }} + + proving_key->contains_recursive_proof = false; + + return proving_key; +}} + +std::shared_ptr {name}Composer::compute_verification_key( + CircuitConstructor& circuit_constructor) +{{ + if (verification_key) {{ + return verification_key; + }} + + if (!proving_key) {{ + compute_proving_key(circuit_constructor); + }} + + verification_key = + std::make_shared(proving_key->circuit_size, proving_key->num_public_inputs); + + return verification_key; +}} + +}} +"); + self.write_file( + &self.composer, + &format!("{}_composer.cpp", snake_case(name)), + &composer_cpp, + ); + } + + fn create_composer_hpp(&mut self, name: &str) { + let include_str = hpp_includes(&snake_case(name)); + + let composer_hpp = format!( + " +{include_str} + +namespace bb {{ +class {name}Composer {{ + public: + using Flavor = {name}Flavor; + using CircuitConstructor = {name}CircuitBuilder; + using ProvingKey = Flavor::ProvingKey; + using VerificationKey = Flavor::VerificationKey; + using PCS = Flavor::PCS; + using CommitmentKey = Flavor::CommitmentKey; + using VerifierCommitmentKey = Flavor::VerifierCommitmentKey; + + // TODO: which of these will we really need + static constexpr std::string_view NAME_STRING = \"{name}\"; + static constexpr size_t NUM_RESERVED_GATES = 0; + static constexpr size_t NUM_WIRES = Flavor::NUM_WIRES; + + std::shared_ptr proving_key; + std::shared_ptr verification_key; + + // The crs_factory holds the path to the srs and exposes methods to extract the srs elements + std::shared_ptr> crs_factory_; + + // The commitment key is passed to the prover but also used herein to compute the verfication key commitments + std::shared_ptr commitment_key; + + std::vector recursive_proof_public_input_indices; + bool contains_recursive_proof = false; + bool computed_witness = false; + + {name}Composer() + {{ + crs_factory_ = bb::srs::get_bn254_crs_factory(); + }} + + {name}Composer(std::shared_ptr p_key, std::shared_ptr v_key) + : proving_key(std::move(p_key)) + , verification_key(std::move(v_key)) + {{}} + + {name}Composer({name}Composer&& other) noexcept = default; + {name}Composer({name}Composer const& other) noexcept = default; + {name}Composer& operator=({name}Composer&& other) noexcept = default; + {name}Composer& operator=({name}Composer const& other) noexcept = default; + ~{name}Composer() = default; + + std::shared_ptr compute_proving_key(CircuitConstructor& circuit_constructor); + std::shared_ptr compute_verification_key(CircuitConstructor& circuit_constructor); + + void compute_witness(CircuitConstructor& circuit_constructor); + + {name}Prover create_prover(CircuitConstructor& circuit_constructor); + {name}Verifier create_verifier(CircuitConstructor& circuit_constructor); + + void add_table_column_selector_poly_to_proving_key(bb::polynomial& small, const std::string& tag); + + void compute_commitment_key(size_t circuit_size) + {{ + proving_key->commitment_key = std::make_shared(circuit_size); + }}; +}}; + +}} // namespace bb +" + ); + + self.write_file( + &self.composer, + &format!("{}_composer.hpp", snake_case(name)), + &composer_hpp, + ); + } +} + +fn cpp_includes(name: &str) -> String { + format!( + " +#include \"./{name}_composer.hpp\" +#include \"barretenberg/plonk_honk_shared/composer/composer_lib.hpp\" +#include \"barretenberg/plonk_honk_shared/composer/permutation_lib.hpp\" +#include \"barretenberg/vm/generated/{name}_circuit_builder.hpp\" +#include \"barretenberg/vm/generated/{name}_verifier.hpp\" +" + ) +} + +pub fn hpp_includes(name: &str) -> String { + format!( + " +#pragma once + +#include \"barretenberg/plonk_honk_shared/composer/composer_lib.hpp\" +#include \"barretenberg/srs/global_crs.hpp\" +#include \"barretenberg/vm/generated/{name}_circuit_builder.hpp\" +#include \"barretenberg/vm/generated/{name}_prover.hpp\" +#include \"barretenberg/vm/generated/{name}_verifier.hpp\" + " + ) +} diff --git a/bb-pilcom/bb-pil-backend/src/file_writer.rs b/bb-pilcom/bb-pil-backend/src/file_writer.rs new file mode 100644 index 00000000000..a4ed8e1e55e --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/file_writer.rs @@ -0,0 +1,58 @@ +use std::fs::File; +use std::io::Write; + +pub struct BBFiles { + // Relative paths + pub file_name: String, + pub base: String, + pub rel: String, + pub circuit: String, + pub flavor: String, + pub composer: String, + pub prover: String, // path for both prover and verifier files +} + +impl BBFiles { + pub fn default(file_name: String) -> Self { + Self::new(file_name, None, None, None, None, None, None) + } + + #[allow(clippy::too_many_arguments)] + pub fn new( + file_name: String, + base: Option, + rel: Option, + circuit: Option, + flavor: Option, + composer: Option, + prover: Option, + ) -> Self { + let base = base.unwrap_or("src/barretenberg".to_owned()); + let rel = rel.unwrap_or("relations/generated".to_owned()); + let circuit = circuit.unwrap_or("vm/generated".to_owned()); + let flavor = flavor.unwrap_or("vm/generated".to_owned()); + let composer = composer.unwrap_or("vm/generated".to_owned()); + let prover = prover.unwrap_or("vm/generated".to_owned()); + + Self { + file_name, + + base, + rel, + circuit, + flavor, + composer, + prover, + } + } + + pub fn write_file(&self, folder: &str, filename: &str, contents: &String) { + // attempt to create dir + let base_path = format!("{}/{}", self.base, folder); + let _ = std::fs::create_dir_all(&base_path); + + let joined = format!("{}/{}", base_path, filename); + let mut file = File::create(joined).unwrap(); + file.write_all(contents.as_bytes()).unwrap(); + } +} diff --git a/bb-pilcom/bb-pil-backend/src/flavor_builder.rs b/bb-pilcom/bb-pil-backend/src/flavor_builder.rs new file mode 100644 index 00000000000..dab4058bdfe --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/flavor_builder.rs @@ -0,0 +1,629 @@ +use crate::{ + file_writer::BBFiles, + utils::{get_relations_imports, map_with_newline, snake_case}, +}; + +pub trait FlavorBuilder { + #[allow(clippy::too_many_arguments)] + fn create_flavor_hpp( + &mut self, + name: &str, + relation_file_names: &[String], + lookups: &[String], + fixed: &[String], + witness: &[String], + all_cols: &[String], + to_be_shifted: &[String], + shifted: &[String], + all_cols_and_shifts: &[String], + ); +} + +/// Build the boilerplate for the flavor file +impl FlavorBuilder for BBFiles { + fn create_flavor_hpp( + &mut self, + name: &str, + relation_file_names: &[String], + lookups: &[String], + fixed: &[String], + witness: &[String], + all_cols: &[String], + to_be_shifted: &[String], + shifted: &[String], + all_cols_and_shifts: &[String], + ) { + let first_poly = &witness[0]; + let includes = flavor_includes(&snake_case(name), relation_file_names, lookups); + let num_precomputed = fixed.len(); + let num_witness = witness.len(); + let num_all = all_cols_and_shifts.len(); + + // Top of file boilerplate + let class_aliases = create_class_aliases(); + let relation_definitions = create_relation_definitions(name, relation_file_names, lookups); + let container_size_definitions = + container_size_definitions(num_precomputed, num_witness, num_all); + + // Entities classes + let precomputed_entities = create_precomputed_entities(fixed); + let witness_entities = create_witness_entities(witness); + let all_entities = + create_all_entities(all_cols, to_be_shifted, shifted, all_cols_and_shifts); + + let proving_and_verification_key = + create_proving_and_verification_key(name, lookups, to_be_shifted); + let polynomial_views = create_polynomial_views(first_poly); + + let commitment_labels_class = create_commitment_labels(all_cols); + + let verification_commitments = create_verifier_commitments(fixed); + + let transcript = generate_transcript(witness); + + let flavor_hpp = format!( + " +{includes} + +namespace bb {{ + +class {name}Flavor {{ + public: + {class_aliases} + + {container_size_definitions} + + {relation_definitions} + + static constexpr bool has_zero_row = true; + + private: + {precomputed_entities} + + {witness_entities} + + {all_entities} + + + {proving_and_verification_key} + + + {polynomial_views} + + {commitment_labels_class} + + {verification_commitments} + + {transcript} +}}; + +}} // namespace bb + + + " + ); + + self.write_file( + &self.flavor, + &format!("{}_flavor.hpp", snake_case(name)), + &flavor_hpp, + ); + } +} + +/// Imports located at the top of the flavor files +fn flavor_includes(name: &str, relation_file_names: &[String], lookups: &[String]) -> String { + let relation_imports = get_relations_imports(name, relation_file_names, lookups); + + format!( + "#pragma once + +#include \"barretenberg/commitment_schemes/kzg/kzg.hpp\" +#include \"barretenberg/ecc/curves/bn254/g1.hpp\" +#include \"barretenberg/flavor/relation_definitions.hpp\" +#include \"barretenberg/polynomials/barycentric.hpp\" +#include \"barretenberg/polynomials/univariate.hpp\" + +#include \"barretenberg/relations/generic_permutation/generic_permutation_relation.hpp\" + +#include \"barretenberg/flavor/flavor_macros.hpp\" +#include \"barretenberg/transcript/transcript.hpp\" +#include \"barretenberg/polynomials/evaluation_domain.hpp\" +#include \"barretenberg/polynomials/polynomial.hpp\" +#include \"barretenberg/flavor/flavor.hpp\" +{relation_imports} +" + ) +} + +/// Creates comma separated relations tuple file +fn create_relations_tuple(master_name: &str, relation_file_names: &[String]) -> String { + relation_file_names + .iter() + .map(|name| format!("{master_name}_vm::{name}")) + .collect::>() + .join(", ") +} + +/// Creates comma separated relations tuple file +fn create_lookups_tuple(lookups: &[String]) -> Option { + if lookups.is_empty() { + return None; + } + Some( + lookups + .iter() + .map(|lookup| format!("{}_relation", lookup.clone())) + .collect::>() + .join(", "), + ) +} + +/// Create Class Aliases +/// +/// Contains boilerplate defining key characteristics of the flavor class +fn create_class_aliases() -> &'static str { + r#" + using Curve = curve::BN254; + using G1 = Curve::Group; + using PCS = KZG; + + using FF = G1::subgroup_field; + using Polynomial = bb::Polynomial; + using PolynomialHandle = std::span; + using GroupElement = G1::element; + using Commitment = G1::affine_element; + using CommitmentHandle = G1::affine_element; + using CommitmentKey = bb::CommitmentKey; + using VerifierCommitmentKey = bb::VerifierCommitmentKey; + using RelationSeparator = FF; + "# +} + +/// Create relation definitions +/// +/// Contains all of the boilerplate code required to generate relation definitions. +/// We instantiate the Relations container, which contains a tuple of all of the separate relation file +/// definitions. +/// +/// We then also define some constants, making use of the preprocessor. +fn create_relation_definitions( + name: &str, + relation_file_names: &[String], + lookups: &[String], +) -> String { + // Relations tuple = ns::relation_name_0, ns::relation_name_1, ... ns::relation_name_n (comma speratated) + let comma_sep_relations = create_relations_tuple(name, relation_file_names); + let comma_sep_lookups: Option = create_lookups_tuple(lookups); + + // We only include the grand product relations if we are given lookups + let mut grand_product_relations = String::new(); + let mut all_relations = comma_sep_relations.to_string(); + if let Some(lookups) = comma_sep_lookups { + all_relations = all_relations + &format!(", {lookups}"); + grand_product_relations = format!("using GrandProductRelations = std::tuple<{lookups}>;"); + } + + format!(" + {grand_product_relations} + + using Relations = std::tuple<{all_relations}>; + + static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); + + // BATCHED_RELATION_PARTIAL_LENGTH = algebraic degree of sumcheck relation *after* multiplying by the `pow_zeta` + // random polynomial e.g. For \\sum(x) [A(x) * B(x) + C(x)] * PowZeta(X), relation length = 2 and random relation + // length = 3 + static constexpr size_t BATCHED_RELATION_PARTIAL_LENGTH = MAX_PARTIAL_RELATION_LENGTH + 1; + static constexpr size_t NUM_RELATIONS = std::tuple_size_v; + + template + using ProtogalaxyTupleOfTuplesOfUnivariates = + decltype(create_protogalaxy_tuple_of_tuples_of_univariates()); + using SumcheckTupleOfTuplesOfUnivariates = decltype(create_sumcheck_tuple_of_tuples_of_univariates()); + using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); + ") +} + +/// Create the number of columns boilerplate for the flavor file +fn container_size_definitions( + num_precomputed: usize, + num_witness: usize, + num_all: usize, +) -> String { + format!(" + static constexpr size_t NUM_PRECOMPUTED_ENTITIES = {num_precomputed}; + static constexpr size_t NUM_WITNESS_ENTITIES = {num_witness}; + static constexpr size_t NUM_WIRES = NUM_WITNESS_ENTITIES + NUM_PRECOMPUTED_ENTITIES; + // We have two copies of the witness entities, so we subtract the number of fixed ones (they have no shift), one for the unshifted and one for the shifted + static constexpr size_t NUM_ALL_ENTITIES = {num_all}; + + ") +} + +/// Returns a Ref Vector with the given name, +/// +/// The vector returned will reference the columns names given +/// Used in all entities declarations +fn return_ref_vector(name: &str, columns: &[String]) -> String { + let comma_sep = create_comma_separated(columns); + + format!("RefVector {name}() {{ return {{ {comma_sep} }}; }};") +} + +/// list -> "list[0], list[1], ... list[n-1]" +fn create_comma_separated(list: &[String]) -> String { + list.join(", ") +} + +/// Create Precomputed Entities +/// +/// Precomputed first contains a pointer view defining all of the precomputed columns +/// As-well as any polys conforming to tables / ids / permutations +fn create_precomputed_entities(fixed: &[String]) -> String { + let pointer_view = create_flavor_members(fixed); + + let selectors = return_ref_vector("get_selectors", fixed); + let sigma_polys = return_ref_vector("get_sigma_polynomials", &[]); + let id_polys = return_ref_vector("get_id_polynomials", &[]); + let table_polys = return_ref_vector("get_table_polynomials", &[]); + + format!( + " + template + class PrecomputedEntities : public PrecomputedEntitiesBase {{ + public: + using DataType = DataType_; + + {pointer_view} + + {selectors} + {sigma_polys} + {id_polys} + {table_polys} + }}; + " + ) +} + +fn create_witness_entities(witness: &[String]) -> String { + let pointer_view = create_flavor_members(witness); + + let wires = return_ref_vector("get_wires", witness); + + format!( + " + template + class WitnessEntities {{ + public: + + {pointer_view} + + {wires} + }}; + " + ) +} + +/// Creates container of all witness entities and shifts +fn create_all_entities( + all_cols: &[String], + to_be_shifted: &[String], + shifted: &[String], + all_cols_and_shifts: &[String], +) -> String { + let all_entities_flavor_members = create_flavor_members(all_cols_and_shifts); + + let wires = return_ref_vector("get_wires", all_cols_and_shifts); + let get_unshifted = return_ref_vector("get_unshifted", all_cols); + let get_to_be_shifted = return_ref_vector("get_to_be_shifted", to_be_shifted); + let get_shifted = return_ref_vector("get_shifted", shifted); + + format!( + " + template + class AllEntities {{ + public: + + {all_entities_flavor_members} + + + {wires} + {get_unshifted} + {get_to_be_shifted} + {get_shifted} + }}; + " + ) +} + +fn create_proving_and_verification_key( + flavor_name: &str, + lookups: &[String], + to_be_shifted: &[String], +) -> String { + let get_to_be_shifted = return_ref_vector("get_to_be_shifted", to_be_shifted); + let compute_logderivative_inverses = + create_compute_logderivative_inverses(flavor_name, lookups); + + format!(" + public: + class ProvingKey : public ProvingKeyAvm_, WitnessEntities, CommitmentKey> {{ + public: + // Expose constructors on the base class + using Base = ProvingKeyAvm_, WitnessEntities, CommitmentKey>; + using Base::Base; + + {get_to_be_shifted} + + {compute_logderivative_inverses} + }}; + + using VerificationKey = VerificationKey_, VerifierCommitmentKey>; + ") +} + +fn create_polynomial_views(first_poly: &String) -> String { + format!(" + + class AllValues : public AllEntities {{ + public: + using Base = AllEntities; + using Base::Base; + }}; + + /** + * @brief A container for the prover polynomials handles. + */ + class ProverPolynomials : public AllEntities {{ + public: + // Define all operations as default, except copy construction/assignment + ProverPolynomials() = default; + ProverPolynomials& operator=(const ProverPolynomials&) = delete; + ProverPolynomials(const ProverPolynomials& o) = delete; + ProverPolynomials(ProverPolynomials&& o) noexcept = default; + ProverPolynomials& operator=(ProverPolynomials&& o) noexcept = default; + ~ProverPolynomials() = default; + + ProverPolynomials(ProvingKey& proving_key) + {{ + for (auto [prover_poly, key_poly] : zip_view(this->get_unshifted(), proving_key.get_all())) {{ + ASSERT(flavor_get_label(*this, prover_poly) == flavor_get_label(proving_key, key_poly)); + prover_poly = key_poly.share(); + }} + for (auto [prover_poly, key_poly] : zip_view(this->get_shifted(), proving_key.get_to_be_shifted())) {{ + ASSERT(flavor_get_label(*this, prover_poly) == (flavor_get_label(proving_key, key_poly) + \"_shift\")); + prover_poly = key_poly.shifted(); + }} + }} + + [[nodiscard]] size_t get_polynomial_size() const {{ return {first_poly}.size(); }} + /** + * @brief Returns the evaluations of all prover polynomials at one point on the boolean hypercube, which + * represents one row in the execution trace. + */ + [[nodiscard]] AllValues get_row(size_t row_idx) const + {{ + AllValues result; + for (auto [result_field, polynomial] : zip_view(result.get_all(), this->get_all())) {{ + result_field = polynomial[row_idx]; + }} + return result; + }} + }}; + + class PartiallyEvaluatedMultivariates : public AllEntities {{ + public: + PartiallyEvaluatedMultivariates() = default; + PartiallyEvaluatedMultivariates(const size_t circuit_size) + {{ + // Storage is only needed after the first partial evaluation, hence polynomials of size (n / 2) + for (auto& poly : get_all()) {{ + poly = Polynomial(circuit_size / 2); + }} + }} + }}; + + /** + * @brief A container for univariates used during Protogalaxy folding and sumcheck. + * @details During folding and sumcheck, the prover evaluates the relations on these univariates. + */ + template + using ProverUnivariates = AllEntities>; + + /** + * @brief A container for univariates used during Protogalaxy folding and sumcheck with some of the computation + * optimistically ignored + * @details During folding and sumcheck, the prover evaluates the relations on these univariates. + */ + template + using OptimisedProverUnivariates = AllEntities>; + + /** + * @brief A container for univariates produced during the hot loop in sumcheck. + */ + using ExtendedEdges = ProverUnivariates; + + /** + * @brief A container for the witness commitments. + * + */ + using WitnessCommitments = WitnessEntities; + + ") +} + +fn create_flavor_members(entities: &[String]) -> String { + let pointer_list = create_comma_separated(entities); + + format!( + "DEFINE_FLAVOR_MEMBERS(DataType, {pointer_list})", + pointer_list = pointer_list + ) +} + +fn create_labels(all_ents: &[String]) -> String { + let mut labels = String::new(); + for name in all_ents { + labels.push_str(&format!( + "Base::{name} = \"{}\"; + ", + name.to_uppercase() + )); + } + labels +} + +fn create_commitment_labels(all_ents: &[String]) -> String { + let labels = create_labels(all_ents); + + format!( + " + class CommitmentLabels: public AllEntities {{ + private: + using Base = AllEntities; + + public: + CommitmentLabels() : AllEntities() + {{ + {labels} + }}; + }}; + " + ) +} + +/// Create the compute_logderivative_inverses function +/// +/// If we do not have any lookups, we do not need to include this round +fn create_compute_logderivative_inverses(flavor_name: &str, lookups: &[String]) -> String { + if lookups.is_empty() { + return "".to_string(); + } + + let compute_inverse_transformation = |lookup_name: &String| { + format!("bb::compute_logderivative_inverse<{flavor_name}Flavor, {lookup_name}_relation>(prover_polynomials, relation_parameters, this->circuit_size);") + }; + + let compute_inverses = map_with_newline(lookups, compute_inverse_transformation); + + format!( + " + void compute_logderivative_inverses(const RelationParameters& relation_parameters) + {{ + ProverPolynomials prover_polynomials = ProverPolynomials(*this); + + {compute_inverses} + }} + " + ) +} + +fn create_key_dereference(fixed: &[String]) -> String { + let deref_transformation = |name: &String| format!("{name} = verification_key->{name};"); + + map_with_newline(fixed, deref_transformation) +} + +fn create_verifier_commitments(fixed: &[String]) -> String { + let key_dereference = create_key_dereference(fixed); + + format!( + " + class VerifierCommitments : public AllEntities {{ + private: + using Base = AllEntities; + + public: + VerifierCommitments(const std::shared_ptr& verification_key) + {{ + {key_dereference} + }} + }}; +" + ) +} + +fn generate_transcript(witness: &[String]) -> String { + // Transformations + let declaration_transform = |c: &_| format!("Commitment {c};"); + let deserialize_transform = |name: &_| { + format!( + "{name} = deserialize_from_buffer(Transcript::proof_data, num_frs_read);", + ) + }; + let serialize_transform = + |name: &_| format!("serialize_to_buffer({name}, Transcript::proof_data);"); + + // Perform Transformations + let declarations = map_with_newline(witness, declaration_transform); + let deserialize_wires = map_with_newline(witness, deserialize_transform); + let serialize_wires = map_with_newline(witness, serialize_transform); + + format!(" + class Transcript : public NativeTranscript {{ + public: + uint32_t circuit_size; + + {declarations} + + std::vector> sumcheck_univariates; + std::array sumcheck_evaluations; + std::vector zm_cq_comms; + Commitment zm_cq_comm; + Commitment zm_pi_comm; + + Transcript() = default; + + Transcript(const std::vector& proof) + : NativeTranscript(proof) + {{}} + + void deserialize_full_transcript() + {{ + size_t num_frs_read = 0; + circuit_size = deserialize_from_buffer(proof_data, num_frs_read); + size_t log_n = numeric::get_msb(circuit_size); + + {deserialize_wires} + + for (size_t i = 0; i < log_n; ++i) {{ + sumcheck_univariates.emplace_back( + deserialize_from_buffer>( + Transcript::proof_data, num_frs_read)); + }} + sumcheck_evaluations = deserialize_from_buffer>( + Transcript::proof_data, num_frs_read); + for (size_t i = 0; i < log_n; ++i) {{ + zm_cq_comms.push_back(deserialize_from_buffer(proof_data, num_frs_read)); + }} + zm_cq_comm = deserialize_from_buffer(proof_data, num_frs_read); + zm_pi_comm = deserialize_from_buffer(proof_data, num_frs_read); + }} + + void serialize_full_transcript() + {{ + size_t old_proof_length = proof_data.size(); + Transcript::proof_data.clear(); + size_t log_n = numeric::get_msb(circuit_size); + + serialize_to_buffer(circuit_size, Transcript::proof_data); + + {serialize_wires} + + for (size_t i = 0; i < log_n; ++i) {{ + serialize_to_buffer(sumcheck_univariates[i], Transcript::proof_data); + }} + serialize_to_buffer(sumcheck_evaluations, Transcript::proof_data); + for (size_t i = 0; i < log_n; ++i) {{ + serialize_to_buffer(zm_cq_comms[i], proof_data); + }} + serialize_to_buffer(zm_cq_comm, proof_data); + serialize_to_buffer(zm_pi_comm, proof_data); + + // sanity check to make sure we generate the same length of proof as before. + ASSERT(proof_data.size() == old_proof_length); + }} + }}; + ") +} diff --git a/bb-pilcom/bb-pil-backend/src/lib.rs b/bb-pilcom/bb-pil-backend/src/lib.rs new file mode 100644 index 00000000000..7644c13d1b5 --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/lib.rs @@ -0,0 +1,11 @@ +mod circuit_builder; +mod composer_builder; +mod file_writer; +mod flavor_builder; +pub mod lookup_builder; +pub mod permutation_builder; +mod prover_builder; +mod relation_builder; +mod utils; +mod verifier_builder; +pub mod vm_builder; diff --git a/bb-pilcom/bb-pil-backend/src/lookup_builder.rs b/bb-pilcom/bb-pil-backend/src/lookup_builder.rs new file mode 100644 index 00000000000..50016404a3f --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/lookup_builder.rs @@ -0,0 +1,369 @@ +use crate::{ + file_writer::BBFiles, + utils::{create_get_const_entities, create_get_nonconst_entities, snake_case}, +}; +use itertools::Itertools; +use powdr_ast::{ + analyzed::{AlgebraicExpression, Analyzed, Identity, IdentityKind}, + parsed::SelectedExpressions, +}; +use powdr_number::FieldElement; + +use crate::utils::sanitize_name; + +#[derive(Debug)] +/// Lookup +/// +/// Contains the information required to produce a lookup relation +/// Lookup object and lookup side object are very similar in structure, however they are duplicated for +/// readability. +pub struct Lookup { + /// the name given to the inverse helper column + pub attribute: Option, + /// The name of the counts polynomial that stores the number of times a lookup is read + pub counts_poly: String, + /// the left side of the lookup + pub left: LookupSide, + /// the right side of the lookup + pub right: LookupSide, +} + +#[derive(Debug)] +/// LookupSide +/// +/// One side of a two sided lookup relationship +pub struct LookupSide { + /// -> Option - the selector for the lookup ( on / off toggle ) + selector: Option, + /// The columns involved in this side of the lookup + cols: Vec, +} + +pub trait LookupBuilder { + /// Takes in an AST and works out what lookup relations are needed + /// Note: returns the name of the inverse columns, such that they can be added to the prover in subsequent steps + fn create_lookup_files( + &self, + name: &str, + analyzed: &Analyzed, + ) -> Vec; +} + +impl LookupBuilder for BBFiles { + fn create_lookup_files( + &self, + project_name: &str, + analyzed: &Analyzed, + ) -> Vec { + let lookups: Vec<&Identity>> = analyzed + .identities + .iter() + .filter(|identity| matches!(identity.kind, IdentityKind::Plookup)) + .collect(); + let new_lookups = lookups + .iter() + .map(|lookup| Lookup { + attribute: lookup.attribute.clone().map(|att| att.to_lowercase()), + counts_poly: format!( + "{}_counts", + lookup.attribute.clone().unwrap().to_lowercase() + ), + left: get_lookup_side(&lookup.left), + right: get_lookup_side(&lookup.right), + }) + .collect_vec(); + + create_lookups(self, project_name, &new_lookups); + new_lookups + } +} + +/// The attributes of a lookup contain the name of the inverse, we collect all of these to create the inverse column +pub fn get_inverses_from_lookups(lookups: &[Lookup]) -> Vec { + lookups + .iter() + .map(|lookup| lookup.attribute.clone().unwrap()) + .collect() +} + +pub fn get_counts_from_lookups(lookups: &[Lookup]) -> Vec { + lookups + .iter() + .map(|lookup| lookup.counts_poly.clone()) + .collect() +} + +/// Write the lookup settings files to disk +fn create_lookups(bb_files: &BBFiles, project_name: &str, lookups: &Vec) { + for lookup in lookups { + let lookup_settings = create_lookup_settings_file(lookup); + + let folder = format!("{}/{}", bb_files.rel, &snake_case(project_name)); + let file_name = format!( + "{}{}", + lookup.attribute.clone().unwrap_or("NONAME".to_owned()), + ".hpp".to_owned() + ); + bb_files.write_file(&folder, &file_name, &lookup_settings); + } +} + +/// All relation types eventually get wrapped in the relation type +/// This function creates the export for the relation type so that it can be added to the flavor +fn create_relation_exporter(lookup_name: &str) -> String { + let settings_name = format!("{}_lookup_settings", lookup_name); + let lookup_export = format!("template using {lookup_name}_relation = GenericLookupRelation<{settings_name}, FF_>;"); + let relation_export = format!( + "template using {lookup_name} = GenericLookup<{settings_name}, FF_>;" + ); + + format!( + " + {lookup_export} + {relation_export} + " + ) +} + +fn lookup_settings_includes() -> &'static str { + r#" + #pragma once + + #include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" + + #include + #include + "# +} + +fn create_lookup_settings_file(lookup: &Lookup) -> String { + let columns_per_set = lookup.left.cols.len(); + let lookup_name = lookup + .attribute + .clone() + .expect("Inverse column name must be provided within lookup attribute - #[]"); + let counts_poly_name = lookup.counts_poly.to_owned(); + + // NOTE: https://github.com/AztecProtocol/aztec-packages/issues/3879 + // Settings are not flexible enough to combine inverses + + let lhs_selector = lookup + .left + .selector + .clone() + .expect("Left hand side selector for lookup required"); + let rhs_selector = lookup + .right + .selector + .clone() + .expect("Right hand side selector for lookup required"); + let lhs_cols = lookup.left.cols.clone(); + let rhs_cols = lookup.right.cols.clone(); + + assert!( + lhs_cols.len() == rhs_cols.len(), + "Lookup columns lhs must be the same length as rhs" + ); + + // 0. The polynomial containing the inverse products -> taken from the attributes + // 1. The polynomial with the counts! + // 2. lhs selector + // 3. rhs selector + // 4.. + columns per set. lhs cols + // 4 + columns per set.. . rhs cols + let mut lookup_entities: Vec = [ + lookup_name.clone(), + counts_poly_name.clone(), + lhs_selector.clone(), + rhs_selector.clone(), + ] + .to_vec(); + + lookup_entities.extend(lhs_cols); + lookup_entities.extend(rhs_cols); + + // NOTE: these are hardcoded as 1 for now until more optimizations are required + let read_terms = 1; + let write_terms = 1; + let lookup_tuple_size = columns_per_set; + + // NOTE: hardcoded until optimizations required + let inverse_degree = 4; + let read_term_degree = 0; + let write_term_degree = 0; + let read_term_types = "{0}"; + let write_term_types = "{0}"; + + let lookup_settings_includes = lookup_settings_includes(); + let inverse_polynomial_is_computed_at_row = + create_inverse_computed_at(&lhs_selector, &rhs_selector); + let compute_inverse_exists = create_compute_inverse_exist(&lhs_selector, &rhs_selector); + let const_entities = create_get_const_entities(&lookup_entities); + let nonconst_entities = create_get_nonconst_entities(&lookup_entities); + let relation_exporter = create_relation_exporter(&lookup_name); + + format!( + " + {lookup_settings_includes} + + namespace bb {{ + + /** + * @brief This class contains an example of how to set LookupSettings classes used by the + * GenericLookupRelationImpl class to specify a scaled lookup + * + * @details To create your own lookup: + * 1) Create a copy of this class and rename it + * 2) Update all the values with the ones needed for your lookup + * 3) Update \"DECLARE_LOOKUP_IMPLEMENTATIONS_FOR_ALL_SETTINGS\" and \"DEFINE_LOOKUP_IMPLEMENTATIONS_FOR_ALL_SETTINGS\" to + * include the new settings + * 4) Add the relation with the chosen settings to Relations in the flavor (for example,\"` + * using Relations = std::tuple>;)` + * + */ + class {lookup_name}_lookup_settings {{ + public: + /** + * @brief The number of read terms (how many lookups we perform) in each row + * + */ + static constexpr size_t READ_TERMS = {read_terms}; + /** + * @brief The number of write terms (how many additions to the lookup table we make) in each row + * + */ + static constexpr size_t WRITE_TERMS = {write_terms}; + + /** + * @brief The type of READ_TERM used for each read index (basic and scaled) + * + */ + static constexpr size_t READ_TERM_TYPES[READ_TERMS] = {read_term_types}; + + /** + * @brief They type of WRITE_TERM used for each write index + * + */ + static constexpr size_t WRITE_TERM_TYPES[WRITE_TERMS] = {write_term_types}; + + /** + * @brief How many values represent a single lookup object. This value is used by the automatic read term + * implementation in the relation in case the lookup is a basic or scaled tuple and in the write term if it's a + * basic tuple + * + */ + static constexpr size_t LOOKUP_TUPLE_SIZE = {lookup_tuple_size}; + + /** + * @brief The polynomial degree of the relation telling us if the inverse polynomial value needs to be computed + * + */ + static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE = {inverse_degree}; + + /** + * @brief The degree of the read term if implemented arbitrarily. This value is not used by basic and scaled read + * terms, but will cause compilation error if not defined + * + */ + static constexpr size_t READ_TERM_DEGREE = {read_term_degree}; + + /** + * @brief The degree of the write term if implemented arbitrarily. This value is not used by the basic write + * term, but will cause compilation error if not defined + * + */ + + static constexpr size_t WRITE_TERM_DEGREE = {write_term_degree}; + + /** + * @brief If this method returns true on a row of values, then the inverse polynomial exists at this index. + * Otherwise the value needs to be set to zero. + * + * @details If this is true then the lookup takes place in this row + * + */ + {inverse_polynomial_is_computed_at_row} + + /** + * @brief Subprocedure for computing the value deciding if the inverse polynomial value needs to be checked in this + * row + * + * @tparam Accumulator Type specified by the lookup relation + * @tparam AllEntities Values/Univariates of all entities row + * @param in Value/Univariate of all entities at row/edge + * @return Accumulator + */ + {compute_inverse_exists} + + /** + * @brief Get all the entities for the lookup when need to update them + * + * @details The generic structure of this tuple is described in ./generic_lookup_relation.hpp . The following is + description for the current case: + The entities are returned as a tuple of references in the following order (this is for ): + * - The entity/polynomial used to store the product of the inverse values + * - The entity/polynomial that specifies how many times the lookup table entry at this row has been looked up + * - READ_TERMS entities/polynomials that enable individual lookup operations + * - The entity/polynomial that enables adding an entry to the lookup table in this row + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the basic tuple being looked up as the first read term + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the previous accumulators in the second read term + (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the shifts in the second read term (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing the current accumulators in the second read term + (scaled tuple) + * - LOOKUP_TUPLE_SIZE entities/polynomials representing basic tuples added to the table + * + * @return All the entities needed for the lookup + */ + {const_entities} + + /** + * @brief Get all the entities for the lookup when we only need to read them + * @details Same as in get_const_entities, but nonconst + * + * @return All the entities needed for the lookup + */ + {nonconst_entities} + }}; + + {relation_exporter} + }} + " + ) +} + +fn create_inverse_computed_at(lhs_selector: &String, rhs_selector: &String) -> String { + let lhs_computed_selector = format!("in.{lhs_selector}"); + let rhs_computed_selector = format!("in.{rhs_selector}"); + format!(" + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) {{ + return ({lhs_computed_selector } == 1 || {rhs_computed_selector} == 1); + }}") +} + +fn create_compute_inverse_exist(lhs_selector: &String, rhs_selector: &String) -> String { + let lhs_computed_selector = format!("in.{lhs_selector}"); + let rhs_computed_selector = format!("in.{rhs_selector}"); + format!(" + template static inline auto compute_inverse_exists(const AllEntities& in) {{ + using View = typename Accumulator::View; + const auto is_operation = View({lhs_computed_selector}); + const auto is_table_entry = View({rhs_computed_selector}); + return (is_operation + is_table_entry - is_operation * is_table_entry); + }}") +} + +fn get_lookup_side( + def: &SelectedExpressions>, +) -> LookupSide { + let get_name = |expr: &AlgebraicExpression| match expr { + AlgebraicExpression::Reference(a_ref) => sanitize_name(&a_ref.name), + _ => panic!("Expected reference"), + }; + + LookupSide { + selector: def.selector.as_ref().map(get_name), + cols: def.expressions.iter().map(get_name).collect_vec(), + } +} diff --git a/bb-pilcom/bb-pil-backend/src/permutation_builder.rs b/bb-pilcom/bb-pil-backend/src/permutation_builder.rs new file mode 100644 index 00000000000..b9dbeb0130e --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/permutation_builder.rs @@ -0,0 +1,254 @@ +use crate::{ + file_writer::BBFiles, + utils::{create_get_const_entities, create_get_nonconst_entities, snake_case}, +}; +use itertools::Itertools; +use powdr_ast::{ + analyzed::{AlgebraicExpression, Analyzed, Identity, IdentityKind}, + parsed::SelectedExpressions, +}; +use powdr_number::FieldElement; + +use crate::utils::sanitize_name; + +#[derive(Debug)] +/// Permutation +/// +/// Contains the information required to produce a permutation relation +pub struct Permutation { + /// -> Attribute - the name given to the inverse helper column + pub attribute: Option, + /// -> PermSide - the left side of the permutation + pub left: PermutationSide, + /// -> PermSide - the right side of the permutation + pub right: PermutationSide, +} + +#[derive(Debug)] +/// PermSide +/// +/// One side of a two sided permutation relationship +pub struct PermutationSide { + /// -> Option - the selector for the permutation ( on / off toggle ) + selector: Option, + /// The columns involved in this side of the permutation + cols: Vec, +} + +pub trait PermutationBuilder { + /// Takes in an AST and works out what permutation relations are needed + /// Note: returns the name of the inverse columns, such that they can be added to he prover in subsequent steps + fn create_permutation_files( + &self, + name: &str, + analyzed: &Analyzed, + ) -> Vec; +} + +impl PermutationBuilder for BBFiles { + fn create_permutation_files( + &self, + project_name: &str, + analyzed: &Analyzed, + ) -> Vec { + let perms: Vec<&Identity>> = analyzed + .identities + .iter() + .filter(|identity| matches!(identity.kind, IdentityKind::Permutation)) + .collect(); + let new_perms = perms + .iter() + .map(|perm| Permutation { + attribute: perm.attribute.clone().map(|att| att.to_lowercase()), + left: get_perm_side(&perm.left), + right: get_perm_side(&perm.right), + }) + .collect_vec(); + + create_permutations(self, project_name, &new_perms); + new_perms + } +} + +/// The attributes of a permutation contain the name of the inverse, we collect all of these to create the inverse column +pub fn get_inverses_from_permutations(permutations: &[Permutation]) -> Vec { + permutations + .iter() + .map(|perm| perm.attribute.clone().unwrap()) + .collect() +} + +/// Write the permutation settings files to disk +fn create_permutations(bb_files: &BBFiles, project_name: &str, permutations: &Vec) { + for permutation in permutations { + let perm_settings = create_permutation_settings_file(permutation); + + let folder = format!("{}/{}", bb_files.rel, &snake_case(project_name)); + let file_name = format!( + "{}{}", + permutation.attribute.clone().unwrap_or("NONAME".to_owned()), + ".hpp".to_owned() + ); + bb_files.write_file(&folder, &file_name, &perm_settings); + } +} + +/// All relation types eventually get wrapped in the relation type +/// This function creates the export for the relation type so that it can be added to the flavor +fn create_relation_exporter(permutation_name: &str) -> String { + let settings_name = format!("{}_permutation_settings", permutation_name); + let permutation_export = format!("template using {permutation_name}_relation = GenericPermutationRelation<{settings_name}, FF_>;"); + let relation_export = format!("template using {permutation_name} = GenericPermutation<{settings_name}, FF_>;"); + + format!( + " + {permutation_export} + {relation_export} + " + ) +} + +fn permutation_settings_includes() -> &'static str { + r#" + #pragma once + + #include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" + + #include + #include + "# +} + +fn create_permutation_settings_file(permutation: &Permutation) -> String { + log::trace!("Permutation: {:?}", permutation); + let columns_per_set = permutation.left.cols.len(); + // TODO(md): In the future we will need to condense off the back of this - combining those with the same inverse column + let permutation_name = permutation + .attribute + .clone() + .expect("Inverse column name must be provided using attribute syntax"); + + // This also will need to work for both sides of this ! + let lhs_selector = permutation + .left + .selector + .clone() + .expect("At least one selector must be provided"); + // If a rhs selector is not present, then we use the rhs selector -- TODO(md): maybe we want the default to be always on? + let rhs_selector = permutation + .right + .selector + .clone() + .unwrap_or(lhs_selector.clone()); + + let lhs_cols = permutation.left.cols.clone(); + let rhs_cols = permutation.right.cols.clone(); + + // 0. The polynomial containing the inverse products -> taken from the attributes + // 1. The polynomial enabling the relation (the selector) + // 2. lhs selector + // 3. rhs selector + // 4.. + columns per set. lhs cols + // 4 + columns per set.. . rhs cols + let mut perm_entities: Vec = [ + permutation_name.clone(), + lhs_selector.clone(), + lhs_selector.clone(), + rhs_selector.clone(), + ] + .to_vec(); + + perm_entities.extend(lhs_cols); + perm_entities.extend(rhs_cols); + + let permutation_settings_includes = permutation_settings_includes(); + + let inverse_computed_at = create_inverse_computed_at(&lhs_selector, &rhs_selector); + let const_entities = create_get_const_entities(&perm_entities); + let nonconst_entities = create_get_nonconst_entities(&perm_entities); + let relation_exporter = create_relation_exporter(&permutation_name); + + format!( + " + {permutation_settings_includes} + + namespace bb {{ + + class {permutation_name}_permutation_settings {{ + public: + // This constant defines how many columns are bundled together to form each set. + constexpr static size_t COLUMNS_PER_SET = {columns_per_set}; + + /** + * @brief If this method returns true on a row of values, then the inverse polynomial at this index. Otherwise the + * value needs to be set to zero. + * + * @details If this is true then permutation takes place in this row + */ + {inverse_computed_at} + + /** + * @brief Get all the entities for the permutation when we don't need to update them + * + * @details The entities are returned as a tuple of references in the following order: + * - The entity/polynomial used to store the product of the inverse values + * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of + * the inverse polynomial + * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum + * subrelation + * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum + * subrelation + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) + * + * @return All the entities needed for the permutation + */ + {const_entities} + + /** + * @brief Get all the entities for the permutation when need to update them + * + * @details The entities are returned as a tuple of references in the following order: + * - The entity/polynomial used to store the product of the inverse values + * - The entity/polynomial that switches on the subrelation of the permutation relation that ensures correctness of + * the inverse polynomial + * - The entity/polynomial that enables adding a tuple-generated value from the first set to the logderivative sum + * subrelation + * - The entity/polynomial that enables adding a tuple-generated value from the second set to the logderivative sum + * subrelation + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the first set (N.B. ORDER IS IMPORTANT!) + * - A sequence of COLUMNS_PER_SET entities/polynomials that represent the second set (N.B. ORDER IS IMPORTANT!) + * + * @return All the entities needed for the permutation + */ + {nonconst_entities} + }}; + + {relation_exporter} + }} + " + ) +} + +fn create_inverse_computed_at(lhs_selector: &String, rhs_selector: &String) -> String { + let lhs_computed_selector = format!("in.{lhs_selector}"); + let rhs_computed_selector = format!("in.{rhs_selector}"); + format!(" + template static inline auto inverse_polynomial_is_computed_at_row(const AllEntities& in) {{ + return ({lhs_computed_selector } == 1 || {rhs_computed_selector} == 1); + }}") +} + +fn get_perm_side( + def: &SelectedExpressions>, +) -> PermutationSide { + let get_name = |expr: &AlgebraicExpression| match expr { + AlgebraicExpression::Reference(a_ref) => sanitize_name(&a_ref.name), + _ => panic!("Expected reference"), + }; + + PermutationSide { + selector: def.selector.as_ref().map(get_name), + cols: def.expressions.iter().map(get_name).collect_vec(), + } +} diff --git a/bb-pilcom/bb-pil-backend/src/prover_builder.rs b/bb-pilcom/bb-pil-backend/src/prover_builder.rs new file mode 100644 index 00000000000..be412cf0d57 --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/prover_builder.rs @@ -0,0 +1,331 @@ +use crate::file_writer::BBFiles; +use crate::utils::{map_with_newline, snake_case}; + +pub trait ProverBuilder { + fn create_prover_hpp(&mut self, name: &str); + + fn create_prover_cpp( + &mut self, + name: &str, + commitment_polys: &[String], + lookup_names: &[String], + ); +} + +impl ProverBuilder for BBFiles { + fn create_prover_hpp(&mut self, name: &str) { + let include_str = includes_hpp(&snake_case(name)); + + let prover_hpp = format!(" + {include_str} + namespace bb {{ + + class {name}Prover {{ + + using Flavor = {name}Flavor; + using FF = Flavor::FF; + using PCS = Flavor::PCS; + using PCSCommitmentKey = Flavor::CommitmentKey; + using ProvingKey = Flavor::ProvingKey; + using Polynomial = Flavor::Polynomial; + using ProverPolynomials = Flavor::ProverPolynomials; + using CommitmentLabels = Flavor::CommitmentLabels; + using Transcript = Flavor::Transcript; + + public: + explicit {name}Prover(std::shared_ptr input_key, std::shared_ptr commitment_key); + + void execute_preamble_round(); + void execute_wire_commitments_round(); + void execute_log_derivative_inverse_round(); + void execute_relation_check_rounds(); + void execute_zeromorph_rounds(); + + HonkProof export_proof(); + HonkProof construct_proof(); + + std::shared_ptr transcript = std::make_shared(); + + std::vector public_inputs; + + bb::RelationParameters relation_parameters; + + std::shared_ptr key; + + // Container for spans of all polynomials required by the prover (i.e. all multivariates evaluated by Sumcheck). + ProverPolynomials prover_polynomials; + + CommitmentLabels commitment_labels; + typename Flavor::WitnessCommitments witness_commitments; + + Polynomial quotient_W; + + SumcheckOutput sumcheck_output; + + std::shared_ptr commitment_key; + + using ZeroMorph = ZeroMorphProver_; + + private: + HonkProof proof; + }}; + + }} // namespace bb + + "); + self.write_file( + &self.prover, + &format!("{}_prover.hpp", snake_case(name)), + &prover_hpp, + ); + } + + /// Create the prover cpp file + /// + /// Committed polys are included as we manually unroll all commitments, as we do not commit to everything + fn create_prover_cpp( + &mut self, + name: &str, + commitment_polys: &[String], + lookup_names: &[String], + ) { + let include_str = includes_cpp(&snake_case(name)); + + let polynomial_commitment_phase = create_commitments_phase(commitment_polys); + + let (call_log_derivative_phase, log_derivative_inverse_phase): (String, String) = + if lookup_names.is_empty() { + ("".to_owned(), "".to_owned()) + } else { + ( + "execute_log_derivative_inverse_round();".to_owned(), + create_log_derivative_inverse_round(lookup_names), + ) + }; + + let prover_cpp = format!(" + {include_str} + + namespace bb {{ + + using Flavor = {name}Flavor; + using FF = Flavor::FF; + + /** + * Create {name}Prover from proving key, witness and manifest. + * + * @param input_key Proving key. + * @param input_manifest Input manifest + * + * @tparam settings Settings class. + * */ + {name}Prover::{name}Prover(std::shared_ptr input_key, + std::shared_ptr commitment_key) + : key(input_key) + , commitment_key(commitment_key) + {{ + for (auto [prover_poly, key_poly] : zip_view(prover_polynomials.get_unshifted(), key->get_all())) {{ + ASSERT(bb::flavor_get_label(prover_polynomials, prover_poly) == + bb::flavor_get_label(*key, key_poly)); + prover_poly = key_poly.share(); + }} + for (auto [prover_poly, key_poly] : zip_view(prover_polynomials.get_shifted(), key->get_to_be_shifted())) {{ + ASSERT(bb::flavor_get_label(prover_polynomials, prover_poly) == + bb::flavor_get_label(*key, key_poly) + \"_shift\"); + prover_poly = key_poly.shifted(); + }} + }} + + + /** + * @brief Add circuit size, public input size, and public inputs to transcript + * + */ + void {name}Prover::execute_preamble_round() + {{ + const auto circuit_size = static_cast(key->circuit_size); + + transcript->send_to_verifier(\"circuit_size\", circuit_size); + }} + + /** + * @brief Compute commitments to all of the witness wires (apart from the logderivative inverse wires) + * + */ + void {name}Prover::execute_wire_commitments_round() + {{ + + {polynomial_commitment_phase} + + }} + + void {name}Prover::execute_log_derivative_inverse_round() + {{ + + {log_derivative_inverse_phase} + }} + + /** + * @brief Run Sumcheck resulting in u = (u_1,...,u_d) challenges and all evaluations at u being calculated. + * + */ + void {name}Prover::execute_relation_check_rounds() + {{ + using Sumcheck = SumcheckProver; + + auto sumcheck = Sumcheck(key->circuit_size, transcript); + + FF alpha = transcript->template get_challenge(\"Sumcheck:alpha\"); + std::vector gate_challenges(numeric::get_msb(key->circuit_size)); + + for (size_t idx = 0; idx < gate_challenges.size(); idx++) {{ + gate_challenges[idx] = transcript->template get_challenge(\"Sumcheck:gate_challenge_\" + std::to_string(idx)); + }} + sumcheck_output = sumcheck.prove(prover_polynomials, relation_parameters, alpha, gate_challenges); + }} + + + /** + * @brief Execute the ZeroMorph protocol to prove the multilinear evaluations produced by Sumcheck + * @details See https://hackmd.io/dlf9xEwhTQyE3hiGbq4FsA?view for a complete description of the unrolled protocol. + * + * */ + void {name}Prover::execute_zeromorph_rounds() + {{ + ZeroMorph::prove(prover_polynomials.get_unshifted(), + prover_polynomials.get_to_be_shifted(), + sumcheck_output.claimed_evaluations.get_unshifted(), + sumcheck_output.claimed_evaluations.get_shifted(), + sumcheck_output.challenge, + commitment_key, + transcript); + + }} + + + HonkProof {name}Prover::export_proof() + {{ + proof = transcript->proof_data; + return proof; + }} + + HonkProof {name}Prover::construct_proof() + {{ + // Add circuit size public input size and public inputs to transcript. + execute_preamble_round(); + + // Compute wire commitments + execute_wire_commitments_round(); + + // Compute sorted list accumulator and commitment + {call_log_derivative_phase} + + // Fiat-Shamir: alpha + // Run sumcheck subprotocol. + execute_relation_check_rounds(); + + // Fiat-Shamir: rho, y, x, z + // Execute Zeromorph multilinear PCS + execute_zeromorph_rounds(); + + return export_proof(); + }} + + }} // namespace bb + + + "); + + self.write_file( + &self.prover, + &format!("{}_prover.cpp", snake_case(name)), + &prover_cpp, + ); + } +} + +fn includes_hpp(name: &str) -> String { + format!( + " +#pragma once +#include \"barretenberg/commitment_schemes/zeromorph/zeromorph.hpp\" +#include \"barretenberg/plonk/proof_system/types/proof.hpp\" +#include \"barretenberg/relations/relation_parameters.hpp\" +#include \"barretenberg/sumcheck/sumcheck_output.hpp\" +#include \"barretenberg/transcript/transcript.hpp\" + +#include \"barretenberg/vm/generated/{name}_flavor.hpp\" + + " + ) +} + +fn includes_cpp(name: &str) -> String { + format!( + " + + #include \"{name}_prover.hpp\" + #include \"barretenberg/commitment_schemes/claim.hpp\" + #include \"barretenberg/commitment_schemes/commitment_key.hpp\" + #include \"barretenberg/honk/proof_system/logderivative_library.hpp\" + #include \"barretenberg/honk/proof_system/permutation_library.hpp\" + #include \"barretenberg/plonk_honk_shared/library/grand_product_library.hpp\" + #include \"barretenberg/polynomials/polynomial.hpp\" + #include \"barretenberg/relations/lookup_relation.hpp\" + #include \"barretenberg/relations/permutation_relation.hpp\" + #include \"barretenberg/sumcheck/sumcheck.hpp\" + " + ) +} + +/// Commitment Transform +/// +/// Produces code to perform kzg commitment, then stores in the witness_commitments struct +fn commitment_transform(name: &String) -> String { + format!("witness_commitments.{name} = commitment_key->commit(key->{name});") +} + +/// Send to Verifier Transform +/// +/// Sends commitment produces in commitment_transform to the verifier +fn send_to_verifier_transform(name: &String) -> String { + format!("transcript->send_to_verifier(commitment_labels.{name}, witness_commitments.{name});") +} + +fn create_commitments_phase(polys_to_commit_to: &[String]) -> String { + let all_commit_operations = map_with_newline(polys_to_commit_to, commitment_transform); + let send_to_verifier_operations = + map_with_newline(polys_to_commit_to, send_to_verifier_transform); + + format!( + " + // Commit to all polynomials (apart from logderivative inverse polynomials, which are committed to in the later logderivative phase) + {all_commit_operations} + + // Send all commitments to the verifier + {send_to_verifier_operations} + " + ) +} + +fn create_log_derivative_inverse_round(lookup_operations: &[String]) -> String { + let all_commit_operations = map_with_newline(lookup_operations, commitment_transform); + let send_to_verifier_operations = + map_with_newline(lookup_operations, send_to_verifier_transform); + + format!( + " + auto [beta, gamm] = transcript->template get_challenges(\"beta\", \"gamma\"); + relation_parameters.beta = beta; + relation_parameters.gamma = gamm; + + key->compute_logderivative_inverses(relation_parameters); + + // Commit to all logderivative inverse polynomials + {all_commit_operations} + + // Send all commitments to the verifier + {send_to_verifier_operations} + " + ) +} diff --git a/bb-pilcom/bb-pil-backend/src/relation_builder.rs b/bb-pilcom/bb-pil-backend/src/relation_builder.rs new file mode 100644 index 00000000000..cfae7c85092 --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/relation_builder.rs @@ -0,0 +1,562 @@ +use itertools::Itertools; +use powdr_ast::analyzed::AlgebraicBinaryOperation; +use powdr_ast::analyzed::AlgebraicExpression; +use powdr_ast::analyzed::AlgebraicUnaryOperation; +use powdr_ast::analyzed::Identity; +use powdr_ast::analyzed::{ + AlgebraicBinaryOperator, AlgebraicExpression as Expression, AlgebraicUnaryOperator, + IdentityKind, +}; +use powdr_ast::parsed::SelectedExpressions; +use std::collections::HashMap; +use std::collections::HashSet; +use std::path::Path; + +use powdr_number::{BigUint, DegreeType, FieldElement}; + +use crate::file_writer::BBFiles; +use crate::utils::{capitalize, map_with_newline, snake_case}; + +/// Returned back to the vm builder from the create_relations call +pub struct RelationOutput { + /// A list of the names of the created relations + pub relations: Vec, + /// A list of the names of all of the 'used' shifted polys + pub shifted_polys: Vec, +} + +/// Each created bb Identity is passed around with its degree so as needs to be manually +/// provided for sumcheck +type BBIdentity = (DegreeType, String); + +pub trait RelationBuilder { + /// Create Relations + /// + /// Takes in the ast ( for relations ), groups each of them by file, and then + /// calls 'create relation' for each + /// + /// Relation output is passed back to the caller as the prover requires both: + /// - The shifted polys + /// - The names of the relations files created + fn create_relations( + &self, + root_name: &str, + identities: &[Identity>], + ) -> RelationOutput; + + /// Create Relation + /// + /// Name and root name are required to determine the file path, e.g. it will be in the bberg/relations/generated + /// followed by /root_name/name + /// - root name should be the name provided with the --name flag + /// - name will be a pil namespace + /// + /// - Identities are the identities that will be used to create the relations, they are generated within create_relations + /// - row_type contains all of the columns that the relations namespace touches. + fn create_relation( + &self, + root_name: &str, + name: &str, + sub_relations: &[String], + identities: &[BBIdentity], + row_type: &str, + labels_lookup: String, + ); + + /// Declare views + /// + /// Declare views is a macro that generates a reference for each of the columns + /// This reference will be a span into a sumcheck related object, it must be declared for EACH sub-relation + /// as the sumcheck object is sensitive to the degree of the relation. + fn create_declare_views(&self, name: &str, all_cols_and_shifts: &[String]); +} + +impl RelationBuilder for BBFiles { + fn create_relations( + &self, + file_name: &str, + analyzed_identities: &[Identity>], + ) -> RelationOutput { + // Group relations per file + let grouped_relations: HashMap>>> = + group_relations_per_file(analyzed_identities); + let mut relations = grouped_relations.keys().cloned().collect_vec(); + relations.sort(); + + // Contains all of the rows in each relation, will be useful for creating composite builder types + let mut all_rows: HashMap = HashMap::new(); + let mut shifted_polys: Vec = Vec::new(); + + // ----------------------- Create the relation files ----------------------- + for (relation_name, analyzed_idents) in grouped_relations.iter() { + let IdentitiesOutput { + subrelations, + identities, + collected_cols, + collected_shifts, + expression_labels, + } = create_identities(file_name, analyzed_idents); + + // TODO: This can probably be moved into the create_identities function + let row_type = create_row_type(&capitalize(relation_name), &collected_cols); + + // Aggregate all shifted polys + shifted_polys.extend(collected_shifts); + // Aggregate all rows + all_rows.insert(relation_name.to_owned(), row_type.clone()); + + let labels_lookup = create_relation_labels(relation_name, expression_labels); + self.create_relation( + file_name, + relation_name, + &subrelations, + &identities, + &row_type, + labels_lookup, + ); + } + + shifted_polys.sort(); + relations.sort(); + + RelationOutput { + relations, + shifted_polys, + } + } + + fn create_relation( + &self, + root_name: &str, + name: &str, + sub_relations: &[String], + identities: &[BBIdentity], + row_type: &str, + labels_lookup: String, + ) { + let includes = relation_includes(); + let class_boilerplate = relation_class_boilerplate(name, sub_relations, identities); + let export = get_export(name); + + let relations = format!( + "{includes} +namespace bb::{root_name}_vm {{ + +{row_type}; + +{labels_lookup} + +{class_boilerplate} + +{export} + + }}" + ); + + self.write_file( + &format!("{}/{}", &self.rel, snake_case(root_name)), + &format!("{}.hpp", snake_case(name)), + &relations, + ); + } + + fn create_declare_views(&self, name: &str, all_cols_and_shifts: &[String]) { + let view_transformation = + |name: &String| format!("[[maybe_unused]] auto {name} = View(new_term.{name}); \\"); + let make_view_per_row = map_with_newline(all_cols_and_shifts, view_transformation); + + let declare_views = format!( + " + #define {name}_DECLARE_VIEWS(index) \\ + using Accumulator = typename std::tuple_element::type; \\ + using View = typename Accumulator::View; \\ + {make_view_per_row} + + + " + ); + + self.write_file( + &format!("{}/{}", &self.rel, snake_case(name)), + "declare_views.hpp", + &declare_views, + ); + } +} + +/// Group relations per file +/// +/// The compiler returns all relations in one large vector, however we want to distinguish +/// which files .pil files the relations belong to for later code gen +/// +/// Say we have two files foo.pil and bar.pil +/// foo.pil contains the following relations: +/// - foo1 +/// - foo2 +/// bar.pil contains the following relations: +/// - bar1 +/// - bar2 +/// +/// This function will return a hashmap with the following structure: +/// { +/// "foo": [foo1, foo2], +/// "bar": [bar1, bar2] +/// } +/// +/// This allows us to generate a relation.hpp file containing ONLY the relations for that .pil file +fn group_relations_per_file( + identities: &[Identity>], +) -> HashMap>>> { + identities.iter().cloned().into_group_map_by(|identity| { + identity + .source + .file_name + .as_ref() + .and_then(|file_name| Path::new(file_name.as_ref()).file_stem()) + .map(|stem| stem.to_string_lossy().into_owned()) + .unwrap_or_default() + .replace(".pil", "") + }) +} + +fn relation_class_boilerplate( + name: &str, + sub_relations: &[String], + identities: &[BBIdentity], +) -> String { + // We add one to all degrees because we have an extra scaling factor + let degrees = identities.iter().map(|(d, _)| d + 1).collect(); + let degree_boilerplate = get_degree_boilerplate(degrees); + let relation_code = get_relation_code(sub_relations); + format!( + "template class {name}Impl {{ + public: + using FF = FF_; + + {degree_boilerplate} + + {relation_code} +}};", + ) +} + +fn get_export(name: &str) -> String { + format!( + "template using {name} = Relation<{name}Impl>;", + name = name + ) +} + +fn get_relation_code(ids: &[String]) -> String { + let mut relation_code = r#" + template + void static accumulate( + ContainerOverSubrelations& evals, + const AllEntities& new_term, + [[maybe_unused]] const RelationParameters&, + [[maybe_unused]] const FF& scaling_factor + ){ + + "# + .to_owned(); + for id in ids { + relation_code.push_str(&format!("{}\n", id)); + } + relation_code.push_str("}\n"); + relation_code +} + +fn get_degree_boilerplate(degrees: Vec) -> String { + let num_degrees = degrees.len(); + + let mut degree_boilerplate = format!( + "static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{{\n" + ); + for degree in °rees { + degree_boilerplate.push_str(&format!(" {},\n", degree)); + } + degree_boilerplate.push_str("};"); + + degree_boilerplate +} + +// The include statements required for a new relation file +fn relation_includes() -> &'static str { + r#" +#pragma once +#include "../../relation_parameters.hpp" +#include "../../relation_types.hpp" +#include "./declare_views.hpp" +"# +} + +// Each vm will need to have a row which is a combination of all of the witness columns +pub(crate) fn create_row_type(name: &str, all_rows: &[String]) -> String { + let row_transformation = |row: &_| format!(" FF {row} {{}};"); + let all_annotated = map_with_newline(all_rows, row_transformation); + + format!( + "template struct {name}Row {{ + {} + + [[maybe_unused]] static std::vector names(); + }}", + all_annotated, + ) +} + +fn create_identity( + expression: &SelectedExpressions>, + collected_cols: &mut HashSet, + collected_public_identities: &mut HashSet, +) -> Option { + // We want to read the types of operators and then create the appropiate code + + if let Some(expr) = &expression.selector { + let x = craft_expression(expr, collected_cols, collected_public_identities); + log::trace!("expression {:?}", x); + Some(x) + } else { + None + } +} + +// TODO: replace the preamble with a macro so the code looks nicer +fn create_subrelation(index: usize, preamble: String, identity: &mut BBIdentity) -> String { + // \\\ + let id = &identity.1; + + format!( + "//Contribution {index} + {{\n{preamble} + + auto tmp = {id}; + tmp *= scaling_factor; + std::get<{index}>(evals) += tmp; +}}", + ) +} + +fn craft_expression( + expr: &Expression, + // TODO: maybe make state? + collected_cols: &mut HashSet, + collected_public_identities: &mut HashSet, +) -> BBIdentity { + let var_name = match expr { + Expression::Number(n) => { + let number: BigUint = n.to_arbitrary_integer(); + if number.bit_len() < 32 { + return (1, format!("FF({})", number)); + } + if number.bit_len() < 64 { + return (1, format!("FF({}UL)", number)); + } + if number.bit_len() < 256 { + let bytes = number.to_be_bytes(); + let padding_len = 32 - bytes.len(); + + let mut padded_bytes = vec![0; padding_len]; + padded_bytes.extend_from_slice(&bytes); + + let mut chunks: Vec = padded_bytes + .chunks(8) + .map(|chunk| u64::from_be_bytes(chunk.try_into().unwrap())) + .collect(); + + chunks.resize(4, 0); + return ( + 1, + format!( + "FF(uint256_t{{{}UL, {}UL, {}UL, {}UL}})", + chunks[3], chunks[2], chunks[1], chunks[0], + ), + ); + } + unimplemented!("{:?}", expr); + } + Expression::Reference(polyref) => { + let mut poly_name = polyref.name.replace('.', "_").to_string(); + if polyref.next { + // NOTE: Naive algorithm to collect all shifted polys + poly_name = format!("{}_shift", poly_name); + } + collected_cols.insert(poly_name.clone()); + (1, poly_name) + } + Expression::BinaryOperation(AlgebraicBinaryOperation { + left: lhe, + op, + right: rhe, + }) => { + let (ld, lhs) = craft_expression(lhe, collected_cols, collected_public_identities); + let (rd, rhs) = craft_expression(rhe, collected_cols, collected_public_identities); + + let degree = std::cmp::max(ld, rd); + match op { + AlgebraicBinaryOperator::Add => match lhe.as_ref() { + // BBerg hack, we do not want a field on the lhs of an expression + Expression::Number(_) => (degree, format!("({} + {})", rhs, lhs)), + _ => (degree, format!("({} + {})", lhs, rhs)), + }, + AlgebraicBinaryOperator::Sub => match lhe.as_ref() { + // BBerg hack, we do not want a field on the lhs of an expression + Expression::Number(_) => (degree, format!("(-{} + {})", rhs, lhs)), + _ => (degree, format!("({} - {})", lhs, rhs)), + }, + AlgebraicBinaryOperator::Mul => match lhe.as_ref() { + // BBerg hack, we do not want a field on the lhs of an expression + Expression::Number(_) => (ld + rd, format!("({} * {})", rhs, lhs)), + _ => (ld + rd, format!("({} * {})", lhs, rhs)), + }, + _ => unimplemented!("{:?}", expr), + } + } + Expression::UnaryOperation(AlgebraicUnaryOperation { + op: operator, + expr: expression, + }) => match operator { + AlgebraicUnaryOperator::Minus => { + let (d, e) = + craft_expression(expression, collected_cols, collected_public_identities); + (d, format!("-{}", e)) + } + }, + // TODO: for now we do nothing with calls to public identities + // These probably can be implemented as some form of copy, however im not sure how we are going to process these down the line + Expression::PublicReference(name) => { + // We collect them for now to warn the user what is going on + collected_public_identities.insert(name.clone()); + (1, "FF(0)".to_string()) + } + // Note: challenges are not being used in our current pil construction + Expression::Challenge(_) => unimplemented!("{:?}", expr), + }; + var_name +} + +pub struct IdentitiesOutput { + subrelations: Vec, + identities: Vec, + collected_cols: Vec, + collected_shifts: Vec, + expression_labels: HashMap, +} + +pub(crate) fn create_identities( + file_name: &str, + identities: &[Identity>], +) -> IdentitiesOutput { + // We only want the expressions for now + // When we have a poly type, we only need the left side of it + let ids = identities + .iter() + .filter(|identity| identity.kind == IdentityKind::Polynomial) + .collect::>(); + + let mut identities = Vec::new(); + let mut subrelations = Vec::new(); + let mut expression_labels: HashMap = HashMap::new(); // Each relation can be given a label, this label can be assigned here + let mut collected_cols: HashSet = HashSet::new(); + let mut collected_public_identities: HashSet = HashSet::new(); + + // Collect labels for each identity + // TODO: shite + for (i, id) in ids.iter().enumerate() { + if let Some(label) = &id.attribute { + expression_labels.insert(i, label.clone()); + } + } + + let expressions = ids.iter().map(|id| id.left.clone()).collect::>(); + for (i, expression) in expressions.iter().enumerate() { + let relation_boilerplate = format!( + "{file_name}_DECLARE_VIEWS({i}); + ", + ); + + // TODO: collected pattern is shit + let mut identity = create_identity( + expression, + &mut collected_cols, + &mut collected_public_identities, + ) + .unwrap(); + let subrelation = create_subrelation(i, relation_boilerplate, &mut identity); + + identities.push(identity); + + subrelations.push(subrelation); + } + + // Print a warning to the user about usage of public identities + if !collected_public_identities.is_empty() { + log::warn!( + "Public Identities are not supported yet in codegen, however some were collected" + ); + log::warn!("Public Identities: {:?}", collected_public_identities); + } + + let mut collected_cols: Vec = collected_cols.drain().collect(); + let mut collected_shifts: Vec = collected_cols + .clone() + .iter() + .filter_map(|col| { + if col.ends_with("shift") { + Some(col.clone()) + } else { + None + } + }) + .collect(); + + collected_cols.sort(); + collected_shifts.sort(); + + IdentitiesOutput { + subrelations, + identities, + collected_cols, + collected_shifts, + expression_labels, + } +} + +/// Relation labels +/// +/// To view relation labels we create a sparse switch that contains all of the collected labels +/// Whenever there is a failure, we can lookup into this mapping +/// +/// Note: this mapping will never be that big, so we are quite naive in implementation +/// It should be able to be called from else where with relation_name::get_relation_label +fn create_relation_labels(relation_name: &str, labels: HashMap) -> String { + // Sort labels by the index + let label_transformation = |(index, label)| { + format!( + "case {index}: + return \"{label}\"; + " + ) + }; + + // Sort the labels by their index + let mut sorted_labels: Vec<(usize, String)> = labels.into_iter().collect(); + sorted_labels.sort_by(|a, b| a.0.cmp(&b.0)); + + let switch_statement: String = sorted_labels + .into_iter() + .map(label_transformation) + .collect::>() + .join("\n"); + + format!( + " + inline std::string get_relation_label_{relation_name}(int index) {{ + switch (index) {{ + {switch_statement} + }} + return std::to_string(index); + }} + " + ) +} diff --git a/bb-pilcom/bb-pil-backend/src/utils.rs b/bb-pilcom/bb-pil-backend/src/utils.rs new file mode 100644 index 00000000000..f84dfac2f1d --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/utils.rs @@ -0,0 +1,145 @@ +use itertools::Itertools; + +/// Get Relations Imports +/// +/// We may have multiple relation files in the generated foler +/// This method will return all of the imports for the relation header files +pub fn get_relations_imports(name: &str, relations: &[String], permutations: &[String]) -> String { + let all_relations = flatten(&[relations.to_vec(), permutations.to_vec()]); + let transformation = |relation_name: &_| { + format!("#include \"barretenberg/relations/generated/{name}/{relation_name}.hpp\"") + }; + + map_with_newline(&all_relations, transformation) +} + +/// Sanitize Names +/// +/// Column titles that we get from pil contain . to distinguish which pil namespace they belong to +/// We need to replace these with _ to make them valid C++ identifiers +pub fn sanitize_name(string: &str) -> String { + string.replace(['.', '[', ']'], "_") +} + +/// Capitalize +pub fn capitalize(s: &str) -> String { + let mut c = s.chars(); + match c.next() { + None => String::new(), + Some(f) => f.to_uppercase().collect::() + c.as_str(), + } +} + +/// Map With Newline +/// This utility function is used all over the codegen pipeline +/// It takes a list, usually the names of columns in an execution trace and applies a string transformation "op" +/// to each element in the list +pub fn map_with_newline(list: &[String], op: Func) -> String +where + Func: Fn(&String) -> String, +{ + transform_map(list, op).join("\n") +} + +/// Collect Col +/// +/// Transforms columns from powdr representation ( where the witnesses are linked ) +/// Into a version where we just keep the columns +/// As this is all we are about +pub fn collect_col(list: &[String], op: Func) -> Vec +where + Func: Fn(&String) -> String, +{ + list.iter().map(op).collect::>() +} + +/// Transform Map +/// +/// Apply a transformation to a list of strings +pub fn transform_map(list: &[String], op: Func) -> Vec +where + Func: Fn(&String) -> String, +{ + list.iter().map(op).collect::>() +} + +/// Flatten +/// +/// Returns a flattened concatenation of the input arrays +pub fn flatten(list: &[Vec]) -> Vec { + let arr = list.iter().cloned(); + arr.into_iter().flatten().collect() +} + +/// Create Forward As Tuple +/// +/// Helper function to create a forward as tuple cpp statement +pub fn create_forward_as_tuple(settings: &[String]) -> String { + let adjusted = settings.iter().map(|col| format!("in.{col}")).join(",\n"); + format!( + " + return std::forward_as_tuple( + {} + ); + ", + adjusted + ) +} + +// TODO: may make sense to move the below around a bit +pub fn create_get_const_entities(settings: &[String]) -> String { + let forward = create_forward_as_tuple(settings); + format!( + " + template static inline auto get_const_entities(const AllEntities& in) {{ + {forward} + }} + " + ) +} + +pub fn create_get_nonconst_entities(settings: &[String]) -> String { + let forward = create_forward_as_tuple(settings); + format!( + " + template static inline auto get_nonconst_entities(AllEntities& in) {{ + {forward} + }} + " + ) +} + +/// Snake Case +/// +/// Transform camel case string into snake case, such as: RedFlower --> red_flower +pub fn snake_case(input: &str) -> String { + let mut result = String::new(); + + // Handle the first character + if input.is_empty() { + return result; // Empty input + } + let mut first_char = input.chars().next().unwrap(); + if first_char.is_uppercase() { + first_char = first_char.to_ascii_lowercase(); + } + result.push(first_char); + + // Process remaining characters + for ch in input.chars().skip(1) { + if ch.is_uppercase() { + result.push('_'); + result.push(ch.to_ascii_lowercase()); + } else { + result.push(ch); + } + } + + result +} + +pub fn sort_cols(cols: &[String]) -> Vec { + let mut cols = cols.to_vec(); + cols.sort(); + cols +} diff --git a/bb-pilcom/bb-pil-backend/src/verifier_builder.rs b/bb-pilcom/bb-pil-backend/src/verifier_builder.rs new file mode 100644 index 00000000000..710b9cafadc --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/verifier_builder.rs @@ -0,0 +1,286 @@ +use crate::{ + file_writer::BBFiles, + utils::{map_with_newline, snake_case}, +}; + +pub trait VerifierBuilder { + fn create_verifier_cpp( + &mut self, + name: &str, + witness: &[String], + inverses: &[String], + public_cols: &[(String, usize)], + ); + + fn create_verifier_hpp(&mut self, name: &str, public_cols: &[(String, usize)]); +} + +impl VerifierBuilder for BBFiles { + fn create_verifier_cpp( + &mut self, + name: &str, + witness: &[String], + inverses: &[String], + public_cols: &[(String, usize)], + ) { + let include_str = includes_cpp(&snake_case(name)); + + let wire_transformation = |n: &String| { + format!( + "commitments.{n} = transcript->template receive_from_prover(commitment_labels.{n});" + ) + }; + let wire_commitments = map_with_newline(witness, wire_transformation); + + let has_public_input_columns = !public_cols.is_empty(); + let has_inverses = !inverses.is_empty(); + + let get_inverse_challenges = if has_inverses { + " + auto [beta, gamm] = transcript->template get_challenges(\"beta\", \"gamma\"); + relation_parameters.beta = beta; + relation_parameters.gamma = gamm; + " + .to_string() + } else { + "".to_owned() + }; + + let verify_proof_function_declaration: String = if has_public_input_columns { + format!("bool {name}Verifier::verify_proof(const HonkProof& proof, const std::vector>& public_inputs)") + } else { + format!("bool {name}Verifier::verify_proof(const HonkProof& proof)") + }; + + let public_inputs_column_transformation = + |public_inputs_column_name: &String, idx: usize| { + format!( + " + FF {public_inputs_column_name}_evaluation = evaluate_public_input_column(public_inputs[{idx}], circuit_size, multivariate_challenge); + if ({public_inputs_column_name}_evaluation != claimed_evaluations.{public_inputs_column_name}) {{ + return false; + }} + " + ) + }; + + let (public_inputs_check, evaluate_public_inputs) = if has_public_input_columns { + let inputs_check = public_cols + .iter() + .map(|(col_name, idx)| public_inputs_column_transformation(col_name, *idx)) + .collect::(); + + let evaluate_public_inputs = format!( + " + + using FF = {name}Flavor::FF; + + // Evaluate the given public input column over the multivariate challenge points + [[maybe_unused]] inline FF evaluate_public_input_column(const std::vector& points, const size_t circuit_size, std::vector challenges) {{ + + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/6361): we pad the points to the circuit size in order to get the correct evaluation. + // This is not efficient, and will not be valid in production. + std::vector new_points(circuit_size, 0); + std::copy(points.begin(), points.end(), new_points.data()); + + Polynomial polynomial(new_points); + return polynomial.evaluate_mle(challenges); + }} + " + ); + + (inputs_check, evaluate_public_inputs) + } else { + ("".to_owned(), "".to_owned()) + }; + + let inverse_commitments = map_with_newline(inverses, wire_transformation); + + let ver_cpp = format!(" +{include_str} + + namespace bb {{ + + + {name}Verifier::{name}Verifier(std::shared_ptr verifier_key) + : key(verifier_key) + {{}} + + {name}Verifier::{name}Verifier({name}Verifier&& other) noexcept + : key(std::move(other.key)) + , pcs_verification_key(std::move(other.pcs_verification_key)) + {{}} + + {name}Verifier& {name}Verifier::operator=({name}Verifier&& other) noexcept + {{ + key = other.key; + pcs_verification_key = (std::move(other.pcs_verification_key)); + commitments.clear(); + return *this; + }} + + {evaluate_public_inputs} + + + /** + * @brief This function verifies an {name} Honk proof for given program settings. + * + */ + {verify_proof_function_declaration} + {{ + using Flavor = {name}Flavor; + using FF = Flavor::FF; + using Commitment = Flavor::Commitment; + // using PCS = Flavor::PCS; + // using ZeroMorph = ZeroMorphVerifier_; + using VerifierCommitments = Flavor::VerifierCommitments; + using CommitmentLabels = Flavor::CommitmentLabels; + + RelationParameters relation_parameters; + + transcript = std::make_shared(proof); + + VerifierCommitments commitments {{ key }}; + CommitmentLabels commitment_labels; + + const auto circuit_size = transcript->template receive_from_prover(\"circuit_size\"); + + if (circuit_size != key->circuit_size) {{ + return false; + }} + + // Get commitments to VM wires + {wire_commitments} + + {get_inverse_challenges} + + // Get commitments to inverses + {inverse_commitments} + + // Execute Sumcheck Verifier + const size_t log_circuit_size = numeric::get_msb(circuit_size); + auto sumcheck = SumcheckVerifier(log_circuit_size, transcript); + + FF alpha = transcript->template get_challenge(\"Sumcheck:alpha\"); + + auto gate_challenges = std::vector(log_circuit_size); + for (size_t idx = 0; idx < log_circuit_size; idx++) {{ + gate_challenges[idx] = transcript->template get_challenge(\"Sumcheck:gate_challenge_\" + std::to_string(idx)); + }} + + auto [multivariate_challenge, claimed_evaluations, sumcheck_verified] = + sumcheck.verify(relation_parameters, alpha, gate_challenges); + + // If Sumcheck did not verify, return false + if (sumcheck_verified.has_value() && !sumcheck_verified.value()) {{ + return false; + }} + + // Public columns evaluation checks + {public_inputs_check} + + // Execute ZeroMorph rounds. See https://hackmd.io/dlf9xEwhTQyE3hiGbq4FsA?view for a complete description of the + // unrolled protocol. + // NOTE: temporarily disabled - facing integration issues + // auto pairing_points = ZeroMorph::verify(commitments.get_unshifted(), + // commitments.get_to_be_shifted(), + // claimed_evaluations.get_unshifted(), + // claimed_evaluations.get_shifted(), + // multivariate_challenge, + // transcript); + + // auto verified = pcs_verification_key->pairing_check(pairing_points[0], pairing_points[1]); + // return sumcheck_verified.value() && verified; + return sumcheck_verified.value(); + }} + + + }} // namespace bb + + + "); + + self.write_file( + &self.prover, + &format!("{}_verifier.cpp", snake_case(name)), + &ver_cpp, + ); + } + + fn create_verifier_hpp(&mut self, name: &str, public_cols: &[(String, usize)]) { + let include_str = include_hpp(&snake_case(name)); + + // If there are public input columns, then the generated verifier must take them in as an argument for the verify_proof + let verify_proof = if !public_cols.is_empty() { + "bool verify_proof(const HonkProof& proof, const std::vector>& public_inputs);" + .to_string() + } else { + "bool verify_proof(const HonkProof& proof);".to_owned() + }; + + let ver_hpp = format!( + " +{include_str} + + namespace bb {{ + class {name}Verifier {{ + using Flavor = {name}Flavor; + using FF = Flavor::FF; + using Commitment = Flavor::Commitment; + using VerificationKey = Flavor::VerificationKey; + using VerifierCommitmentKey = Flavor::VerifierCommitmentKey; + using Transcript = Flavor::Transcript; + + public: + explicit {name}Verifier(std::shared_ptr verifier_key = nullptr); + {name}Verifier({name}Verifier&& other) noexcept; + {name}Verifier(const {name}Verifier& other) = delete; + + {name}Verifier& operator=(const {name}Verifier& other) = delete; + {name}Verifier& operator=({name}Verifier&& other) noexcept; + + {verify_proof} + + std::shared_ptr key; + std::map commitments; + std::shared_ptr pcs_verification_key; + std::shared_ptr transcript; + }}; + + }} // namespace bb + + + " + ); + + self.write_file( + &self.prover, + &format!("{}_verifier.hpp", snake_case(name)), + &ver_hpp, + ); + } +} + +fn include_hpp(name: &str) -> String { + format!( + " +#pragma once +#include \"barretenberg/plonk/proof_system/types/proof.hpp\" +#include \"barretenberg/sumcheck/sumcheck.hpp\" +#include \"barretenberg/vm/generated/{name}_flavor.hpp\" +#include \"barretenberg/vm/avm_trace/constants.hpp\" +" + ) +} + +fn includes_cpp(name: &str) -> String { + format!( + " + #include \"./{name}_verifier.hpp\" + #include \"barretenberg/commitment_schemes/zeromorph/zeromorph.hpp\" + #include \"barretenberg/numeric/bitop/get_msb.hpp\" + #include \"barretenberg/polynomials/polynomial.hpp\" + #include \"barretenberg/transcript/transcript.hpp\" + " + ) +} diff --git a/bb-pilcom/bb-pil-backend/src/vm_builder.rs b/bb-pilcom/bb-pil-backend/src/vm_builder.rs new file mode 100644 index 00000000000..8707ef40a45 --- /dev/null +++ b/bb-pilcom/bb-pil-backend/src/vm_builder.rs @@ -0,0 +1,236 @@ +use powdr_ast::analyzed::Analyzed; +use powdr_number::FieldElement; + +use crate::circuit_builder::CircuitBuilder; +use crate::composer_builder::ComposerBuilder; +use crate::file_writer::BBFiles; +use crate::flavor_builder::FlavorBuilder; +use crate::lookup_builder::get_counts_from_lookups; +use crate::lookup_builder::get_inverses_from_lookups; +use crate::lookup_builder::Lookup; +use crate::lookup_builder::LookupBuilder; +use crate::permutation_builder::get_inverses_from_permutations; +use crate::permutation_builder::Permutation; +use crate::permutation_builder::PermutationBuilder; +use crate::prover_builder::ProverBuilder; +use crate::relation_builder::RelationBuilder; +use crate::relation_builder::RelationOutput; +use crate::utils::collect_col; +use crate::utils::flatten; +use crate::utils::sanitize_name; +use crate::utils::sort_cols; +use crate::utils::transform_map; +use crate::verifier_builder::VerifierBuilder; + +/// All of the combinations of columns that are used in a bberg flavor file +struct ColumnGroups { + /// fixed or constant columns in pil -> will be found in vk + fixed: Vec, + /// witness or commit columns in pil -> will be found in proof + witness: Vec, + /// witness or commit columns in pil, with out the inverse columns + witnesses_without_inverses: Vec, + /// fixed + witness columns without lookup inverses + all_cols_without_inverses: Vec, + /// fixed + witness columns with lookup inverses + all_cols: Vec, + /// Columns that will not be shifted + unshifted: Vec, + /// Columns that will be shifted + to_be_shifted: Vec, + /// The shifts of the columns that will be shifted + shifted: Vec, + /// fixed + witness + shifted + all_cols_with_shifts: Vec, + /// Inverses from lookups and permuations + inverses: Vec, +} + +/// Analyzed to cpp +/// +/// Converts an analyzed pil AST into a set of cpp files that can be used to generate a proof +pub fn analyzed_to_cpp( + analyzed: &Analyzed, + fixed: &[String], + witness: &[String], + public: &[String], + name: Option, +) { + // Extract public inputs information. + let mut public_inputs: Vec<(String, usize)> = public + .iter() + .enumerate() + .map(|(i, name)| (sanitize_name(name), i)) + .collect(); + public_inputs.sort_by(|a, b| a.1.cmp(&b.1)); + + // Sort fixed and witness to ensure consistent ordering + let fixed = &sort_cols(fixed); + let witness = &sort_cols(witness); + + let file_name: &str = &name.unwrap_or("Example".to_owned()); + let mut bb_files = BBFiles::default(file_name.to_owned()); + + // Inlining step to remove the intermediate poly definitions + let mut analyzed_identities = analyzed.identities_with_inlined_intermediate_polynomials(); + analyzed_identities.sort_by(|a, b| a.id.cmp(&b.id)); + + // ----------------------- Handle Standard Relation Identities ----------------------- + // We collect all references to shifts as we traverse all identities and create relation files + let RelationOutput { + relations, + shifted_polys, + } = bb_files.create_relations(file_name, &analyzed_identities); + + // ----------------------- Handle Lookup / Permutation Relation Identities ----------------------- + let permutations = bb_files.create_permutation_files(file_name, analyzed); + let lookups = bb_files.create_lookup_files(file_name, analyzed); + + // TODO: hack - this can be removed with some restructuring + let shifted_polys: Vec = shifted_polys + .clone() + .iter() + .map(|s| s.replace("_shift", "")) + .collect(); + + // Collect all column names and determine if they need a shift or not + let ColumnGroups { + fixed, + witness, + witnesses_without_inverses, + all_cols, + all_cols_without_inverses, + unshifted: _unshifted, + to_be_shifted, + shifted, + all_cols_with_shifts, + inverses, + } = get_all_col_names( + fixed, + witness, + public, + &shifted_polys, + &permutations, + &lookups, + ); + + bb_files.create_declare_views(file_name, &all_cols_with_shifts); + + // ----------------------- Create the circuit builder file ----------------------- + bb_files.create_circuit_builder_hpp( + file_name, + &relations, + &inverses, + &all_cols_without_inverses, + &all_cols, + &to_be_shifted, + &all_cols_with_shifts, + ); + + bb_files.create_circuit_builder_cpp(file_name, &all_cols); + + // ----------------------- Create the flavor file ----------------------- + bb_files.create_flavor_hpp( + file_name, + &relations, + &inverses, + &fixed, + &witness, + &all_cols, + &to_be_shifted, + &shifted, + &all_cols_with_shifts, + ); + + // ----------------------- Create the composer files ----------------------- + bb_files.create_composer_cpp(file_name); + bb_files.create_composer_hpp(file_name); + + // ----------------------- Create the Verifier files ----------------------- + bb_files.create_verifier_cpp( + file_name, + &witnesses_without_inverses, + &inverses, + &public_inputs, + ); + bb_files.create_verifier_hpp(file_name, &public_inputs); + + // ----------------------- Create the Prover files ----------------------- + bb_files.create_prover_cpp(file_name, &witnesses_without_inverses, &inverses); + bb_files.create_prover_hpp(file_name); +} + +/// Get all col names +/// +/// In the flavor file, there are a number of different groups of columns that we need to keep track of +/// This function will return all of the columns in the following groups: +/// - fixed +/// - witness +/// - all_cols +/// - unshifted +/// - to_be_shifted +/// - all_cols_with_shifts +fn get_all_col_names( + fixed: &[String], + witness: &[String], + public: &[String], + to_be_shifted: &[String], + permutations: &[Permutation], + lookups: &[Lookup], +) -> ColumnGroups { + log::info!("Getting all column names"); + + // Transformations + let sanitize = |name: &String| sanitize_name(name).to_owned(); + let append_shift = |name: &String| format!("{}_shift", *name); + + let perm_inverses = get_inverses_from_permutations(permutations); + let lookup_inverses = get_inverses_from_lookups(lookups); + let lookup_counts = get_counts_from_lookups(lookups); + + // Gather sanitized column names + let fixed_names = collect_col(fixed, sanitize); + let witness_names = collect_col(witness, sanitize); + let public_names = collect_col(public, sanitize); + let inverses = flatten(&[perm_inverses, lookup_inverses]); + let witnesses_without_inverses = flatten(&[ + public_names.clone(), + witness_names.clone(), + lookup_counts.clone(), + ]); + let witnesses_with_inverses = flatten(&[ + public_names.clone(), + witness_names, + inverses.clone(), + lookup_counts, + ]); + + // Group columns by properties + let shifted = transform_map(to_be_shifted, append_shift); + let all_cols_without_inverses: Vec = + flatten(&[fixed_names.clone(), witnesses_without_inverses.clone()]); + let all_cols: Vec = flatten(&[fixed_names.clone(), witnesses_with_inverses.clone()]); + let unshifted: Vec = flatten(&[fixed_names.clone(), witnesses_with_inverses.clone()]) + .into_iter() + .filter(|name| !shifted.contains(name)) + .collect(); + + let all_cols_with_shifts: Vec = flatten(&[ + fixed_names.clone(), + witnesses_with_inverses.clone(), + shifted.clone(), + ]); + + ColumnGroups { + fixed: fixed_names, + witness: witnesses_with_inverses, + all_cols_without_inverses, + witnesses_without_inverses, + all_cols, + unshifted, + to_be_shifted: to_be_shifted.to_vec(), + shifted, + all_cols_with_shifts, + inverses, + } +} diff --git a/bb-pilcom/bootstrap.sh b/bb-pilcom/bootstrap.sh new file mode 100755 index 00000000000..ef8e4c9c117 --- /dev/null +++ b/bb-pilcom/bootstrap.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +cargo build --release \ No newline at end of file diff --git a/bb-pilcom/cli/Cargo.toml b/bb-pilcom/cli/Cargo.toml new file mode 100644 index 00000000000..6f717a88f5f --- /dev/null +++ b/bb-pilcom/cli/Cargo.toml @@ -0,0 +1,26 @@ + +[package] +name = "cli" +version = "0.1.0" +authors = ["Aztec Labs"] +edition = "2021" + +[[bin]] +name = "bb_pil" +path = "src/main.rs" + +[dependencies] +clap = { version = "^4.3", features = ["derive"] } +num-bigint = "0.4.3" +bb-pil-backend ={ path = "../bb-pil-backend" } + +powdr-pil-analyzer ={ path = "../powdr/pil-analyzer" } +powdr-number = { path = "../powdr/number" } +num-traits = "0.2.15" +num-integer = "0.1.45" +itertools = "^0.10" +log = "0.4.17" +rand = "0.8.5" +powdr-ast = { path = "../powdr/ast" } + + diff --git a/bb-pilcom/cli/README.md b/bb-pilcom/cli/README.md new file mode 100644 index 00000000000..9c6fd860593 --- /dev/null +++ b/bb-pilcom/cli/README.md @@ -0,0 +1,3 @@ +## BBERG PIL CLI +A small wrapper around powdr pil that only implements the parts of powdr required for direct pil -> bberg codegen + diff --git a/bb-pilcom/cli/src/main.rs b/bb-pilcom/cli/src/main.rs new file mode 100644 index 00000000000..37f6b4cfd41 --- /dev/null +++ b/bb-pilcom/cli/src/main.rs @@ -0,0 +1,52 @@ +use std::{io, path::Path}; + +use bb_pil_backend::vm_builder::analyzed_to_cpp; +use clap::Parser; +use powdr_ast::analyzed::{Analyzed, FunctionValueDefinition, Symbol}; +use powdr_number::Bn254Field; +use powdr_pil_analyzer::analyze_file; + +#[derive(Parser)] +#[command(name = "bb-pil-cli", author, version, about, long_about = None)] +struct Cli { + /// Input file + file: String, + + /// Output directory for the PIL file, json file and fixed and witness column data. + #[arg(short, long)] + #[arg(default_value_t = String::from("."))] + output_directory: String, + + /// BBerg: Name of the output file for bberg + #[arg(long)] + name: Option, +} + +fn extract_col_name(cols: Vec<&(Symbol, Option)>) -> Vec { + // Note that function val def should be none + cols.iter() + .map(|(sym, _def)| sym.absolute_name.replace(".", "_")) + .collect() +} + +fn main() -> Result<(), io::Error> { + let args = Cli::parse(); + + let file_name = args.file; + let name = args.name; + + let analyzed: Analyzed = analyze_file(Path::new(&file_name)); + + let fixed = analyzed.constant_polys_in_source_order(); + let witness = analyzed.committed_polys_in_source_order(); + let public = analyzed.public_polys_in_source_order(); + + analyzed_to_cpp( + &analyzed, + &extract_col_name(fixed), + &extract_col_name(witness), + &extract_col_name(public), + name, + ); + Ok(()) +} diff --git a/bb-pilcom/powdr b/bb-pilcom/powdr new file mode 160000 index 00000000000..c3006c11819 --- /dev/null +++ b/bb-pilcom/powdr @@ -0,0 +1 @@ +Subproject commit c3006c11819d9b53fb183c9c12a10b83481bb631