From 004bb69d8031851d75a2ac1386fee4b4194d25ba Mon Sep 17 00:00:00 2001 From: fcarreiro Date: Fri, 5 Jul 2024 13:53:54 +0000 Subject: [PATCH] chore(avm): avoid including flavor where possible --- barretenberg/cpp/src/barretenberg/bb/main.cpp | 1 + .../barretenberg/vm/avm_trace/avm_common.hpp | 8 +- .../vm/avm_trace/avm_execution.cpp | 1 - .../vm/avm_trace/avm_execution.hpp | 1 + .../barretenberg/vm/avm_trace/avm_trace.hpp | 1 - .../vm/generated/avm_circuit_builder.hpp | 396 +---------------- .../barretenberg/vm/generated/avm_flavor.hpp | 26 +- .../vm/generated/avm_flavor_settings.hpp | 28 ++ ...m_circuit_builder.cpp => avm_full_row.cpp} | 7 +- .../vm/generated/avm_full_row.hpp | 403 ++++++++++++++++++ .../barretenberg/vm/tests/helpers.test.hpp | 3 +- .../bb-pil-backend/src/circuit_builder.rs | 40 +- .../bb-pil-backend/src/flavor_builder.rs | 26 ++ bb-pilcom/bb-pil-backend/src/vm_builder.rs | 8 +- .../templates/circuit_builder.hpp.hbs | 13 +- .../bb-pil-backend/templates/flavor.hpp.hbs | 28 +- .../templates/flavor_settings.hpp.hbs | 28 ++ ...rcuit_builder.cpp.hbs => full_row.cpp.hbs} | 7 +- .../bb-pil-backend/templates/full_row.hpp.hbs | 20 + 19 files changed, 589 insertions(+), 456 deletions(-) create mode 100644 barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor_settings.hpp rename barretenberg/cpp/src/barretenberg/vm/generated/{avm_circuit_builder.cpp => avm_full_row.cpp} (99%) create mode 100644 barretenberg/cpp/src/barretenberg/vm/generated/avm_full_row.hpp create mode 100644 bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs rename bb-pilcom/bb-pil-backend/templates/{circuit_builder.cpp.hbs => full_row.cpp.hbs} (77%) create mode 100644 bb-pilcom/bb-pil-backend/templates/full_row.hpp.hbs diff --git a/barretenberg/cpp/src/barretenberg/bb/main.cpp b/barretenberg/cpp/src/barretenberg/bb/main.cpp index b21c075ffab..d5cd3e11d82 100644 --- a/barretenberg/cpp/src/barretenberg/bb/main.cpp +++ b/barretenberg/cpp/src/barretenberg/bb/main.cpp @@ -9,6 +9,7 @@ #ifndef DISABLE_AZTEC_VM #include "barretenberg/vm/avm_trace/avm_common.hpp" #include "barretenberg/vm/avm_trace/avm_execution.hpp" +#include "barretenberg/vm/avm_trace/stats.hpp" #endif #include "config.hpp" #include "get_bn254_crs.hpp" diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp index 28cd8bf0fd0..38b9bcbba15 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_common.hpp @@ -3,8 +3,9 @@ #include "barretenberg/common/throw_or_abort.hpp" #include "barretenberg/serialize/msgpack.hpp" #include "barretenberg/vm/avm_trace/constants.hpp" -#include "barretenberg/vm/avm_trace/stats.hpp" -#include "barretenberg/vm/generated/avm_flavor.hpp" + +#include "barretenberg/vm/generated/avm_flavor_settings.hpp" +#include "barretenberg/vm/generated/avm_full_row.hpp" #include #include @@ -13,8 +14,7 @@ namespace bb::avm_trace { -using Flavor = bb::AvmFlavor; -using FF = Flavor::FF; +using FF = AvmFlavorSettings::FF; // To toggle all relevant unit tests with proving, set the env variable "AVM_ENABLE_FULL_PROVING". static const bool ENABLE_PROVING = std::getenv("AVM_ENABLE_FULL_PROVING") != nullptr; diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp index a8ee5e4aaa5..8ba8765aa5c 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.cpp @@ -13,7 +13,6 @@ #include "barretenberg/vm/avm_trace/constants.hpp" #include "barretenberg/vm/generated/avm_circuit_builder.hpp" #include "barretenberg/vm/generated/avm_composer.hpp" -#include "barretenberg/vm/generated/avm_flavor.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp index 2b6175febf1..e9df9f569f0 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_execution.hpp @@ -4,6 +4,7 @@ #include "barretenberg/vm/avm_trace/avm_common.hpp" #include "barretenberg/vm/avm_trace/avm_instructions.hpp" #include "barretenberg/vm/avm_trace/avm_trace.hpp" +#include "barretenberg/vm/generated/avm_flavor.hpp" #include #include diff --git a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp index 51572ae3bfe..01392ef683c 100644 --- a/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp @@ -16,7 +16,6 @@ #include "barretenberg/vm/avm_trace/gadgets/avm_pedersen.hpp" #include "barretenberg/vm/avm_trace/gadgets/avm_poseidon2.hpp" #include "barretenberg/vm/avm_trace/gadgets/avm_sha256.hpp" -#include "barretenberg/vm/generated/avm_circuit_builder.hpp" namespace bb::avm_trace { 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 aee7143e1ba..2bfabec7273 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.hpp @@ -14,405 +14,11 @@ #include "barretenberg/relations/generic_permutation/generic_permutation_relation.hpp" #include "barretenberg/stdlib_circuit_builders/circuit_builder_base.hpp" -// This already imports the relations and permutations. For now we rely on the transitive includes. #include "barretenberg/vm/generated/avm_flavor.hpp" +#include "barretenberg/vm/generated/avm_full_row.hpp" 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 main_calldata{}; - FF alu_a_hi{}; - FF alu_a_lo{}; - FF alu_b_hi{}; - FF alu_b_lo{}; - FF alu_borrow{}; - FF alu_cf{}; - FF alu_clk{}; - FF alu_cmp_rng_ctr{}; - FF alu_div_u16_r0{}; - FF alu_div_u16_r1{}; - FF alu_div_u16_r2{}; - FF alu_div_u16_r3{}; - FF alu_div_u16_r4{}; - FF alu_div_u16_r5{}; - FF alu_div_u16_r6{}; - FF alu_div_u16_r7{}; - FF alu_divisor_hi{}; - FF alu_divisor_lo{}; - FF alu_ff_tag{}; - FF alu_ia{}; - FF alu_ib{}; - FF alu_ic{}; - FF alu_in_tag{}; - FF alu_op_add{}; - FF alu_op_cast{}; - FF alu_op_cast_prev{}; - FF alu_op_div{}; - FF alu_op_div_a_lt_b{}; - FF alu_op_div_std{}; - FF alu_op_eq{}; - FF alu_op_eq_diff_inv{}; - FF alu_op_lt{}; - FF alu_op_lte{}; - FF alu_op_mul{}; - FF alu_op_not{}; - FF alu_op_shl{}; - FF alu_op_shr{}; - FF alu_op_sub{}; - FF alu_p_a_borrow{}; - FF alu_p_b_borrow{}; - FF alu_p_sub_a_hi{}; - FF alu_p_sub_a_lo{}; - FF alu_p_sub_b_hi{}; - FF alu_p_sub_b_lo{}; - FF alu_partial_prod_hi{}; - FF alu_partial_prod_lo{}; - FF alu_quotient_hi{}; - FF alu_quotient_lo{}; - FF alu_remainder{}; - FF alu_res_hi{}; - FF alu_res_lo{}; - FF alu_sel_alu{}; - FF alu_sel_cmp{}; - FF alu_sel_div_rng_chk{}; - FF alu_sel_rng_chk{}; - FF alu_sel_rng_chk_lookup{}; - FF alu_sel_shift_which{}; - FF alu_shift_lt_bit_len{}; - FF alu_t_sub_s_bits{}; - FF alu_two_pow_s{}; - FF alu_two_pow_t_sub_s{}; - FF alu_u128_tag{}; - FF alu_u16_r0{}; - FF alu_u16_r1{}; - FF alu_u16_r10{}; - FF alu_u16_r11{}; - FF alu_u16_r12{}; - FF alu_u16_r13{}; - FF alu_u16_r14{}; - FF alu_u16_r2{}; - FF alu_u16_r3{}; - FF alu_u16_r4{}; - FF alu_u16_r5{}; - FF alu_u16_r6{}; - FF alu_u16_r7{}; - FF alu_u16_r8{}; - FF alu_u16_r9{}; - FF alu_u16_tag{}; - FF alu_u32_tag{}; - FF alu_u64_tag{}; - FF alu_u8_r0{}; - FF alu_u8_r1{}; - FF alu_u8_tag{}; - FF binary_acc_ia{}; - FF binary_acc_ib{}; - FF binary_acc_ic{}; - FF binary_clk{}; - FF binary_ia_bytes{}; - FF binary_ib_bytes{}; - FF binary_ic_bytes{}; - FF binary_in_tag{}; - FF binary_mem_tag_ctr{}; - FF binary_mem_tag_ctr_inv{}; - FF binary_op_id{}; - FF binary_sel_bin{}; - FF binary_start{}; - FF byte_lookup_sel_bin{}; - FF byte_lookup_table_byte_lengths{}; - FF byte_lookup_table_in_tags{}; - FF byte_lookup_table_input_a{}; - FF byte_lookup_table_input_b{}; - FF byte_lookup_table_op_id{}; - FF byte_lookup_table_output{}; - FF conversion_clk{}; - FF conversion_input{}; - FF conversion_num_limbs{}; - FF conversion_radix{}; - FF conversion_sel_to_radix_le{}; - FF gas_da_gas_fixed_table{}; - FF gas_l2_gas_fixed_table{}; - FF gas_sel_gas_cost{}; - FF keccakf1600_clk{}; - FF keccakf1600_input{}; - FF keccakf1600_output{}; - FF keccakf1600_sel_keccakf1600{}; - FF kernel_emit_l2_to_l1_msg_write_offset{}; - FF kernel_emit_note_hash_write_offset{}; - FF kernel_emit_nullifier_write_offset{}; - FF kernel_emit_unencrypted_log_write_offset{}; - FF kernel_kernel_in_offset{}; - FF kernel_kernel_out_offset{}; - FF kernel_l1_to_l2_msg_exists_write_offset{}; - FF kernel_note_hash_exist_write_offset{}; - FF kernel_nullifier_exists_write_offset{}; - FF kernel_nullifier_non_exists_write_offset{}; - FF kernel_q_public_input_kernel_add_to_table{}; - FF kernel_q_public_input_kernel_out_add_to_table{}; - FF kernel_side_effect_counter{}; - FF kernel_sload_write_offset{}; - FF kernel_sstore_write_offset{}; - FF main_abs_da_rem_gas_hi{}; - FF main_abs_da_rem_gas_lo{}; - FF main_abs_l2_rem_gas_hi{}; - FF main_abs_l2_rem_gas_lo{}; - FF main_alu_in_tag{}; - FF main_bin_op_id{}; - FF main_call_ptr{}; - FF main_da_gas_op_cost{}; - FF main_da_gas_remaining{}; - FF main_da_out_of_gas{}; - FF main_ia{}; - FF main_ib{}; - FF main_ic{}; - FF main_id{}; - FF main_id_zero{}; - FF main_ind_addr_a{}; - FF main_ind_addr_b{}; - FF main_ind_addr_c{}; - FF main_ind_addr_d{}; - FF main_internal_return_ptr{}; - FF main_inv{}; - FF main_l2_gas_op_cost{}; - FF main_l2_gas_remaining{}; - FF main_l2_out_of_gas{}; - FF main_mem_addr_a{}; - FF main_mem_addr_b{}; - FF main_mem_addr_c{}; - FF main_mem_addr_d{}; - FF main_op_err{}; - FF main_opcode_val{}; - FF main_pc{}; - FF main_r_in_tag{}; - FF main_rwa{}; - FF main_rwb{}; - FF main_rwc{}; - FF main_rwd{}; - FF main_sel_alu{}; - FF main_sel_bin{}; - FF main_sel_gas_accounting_active{}; - FF main_sel_last{}; - FF main_sel_mem_op_a{}; - FF main_sel_mem_op_activate_gas{}; - FF main_sel_mem_op_b{}; - FF main_sel_mem_op_c{}; - FF main_sel_mem_op_d{}; - FF main_sel_mov_ia_to_ic{}; - FF main_sel_mov_ib_to_ic{}; - FF main_sel_op_add{}; - FF main_sel_op_address{}; - FF main_sel_op_and{}; - FF main_sel_op_block_number{}; - FF main_sel_op_cast{}; - FF main_sel_op_chain_id{}; - FF main_sel_op_cmov{}; - FF main_sel_op_coinbase{}; - FF main_sel_op_dagasleft{}; - FF main_sel_op_div{}; - FF main_sel_op_emit_l2_to_l1_msg{}; - FF main_sel_op_emit_note_hash{}; - FF main_sel_op_emit_nullifier{}; - FF main_sel_op_emit_unencrypted_log{}; - FF main_sel_op_eq{}; - FF main_sel_op_external_call{}; - FF main_sel_op_fdiv{}; - FF main_sel_op_fee_per_da_gas{}; - FF main_sel_op_fee_per_l2_gas{}; - FF main_sel_op_function_selector{}; - FF main_sel_op_get_contract_instance{}; - FF main_sel_op_halt{}; - FF main_sel_op_internal_call{}; - FF main_sel_op_internal_return{}; - FF main_sel_op_jump{}; - FF main_sel_op_jumpi{}; - FF main_sel_op_keccak{}; - FF main_sel_op_l1_to_l2_msg_exists{}; - FF main_sel_op_l2gasleft{}; - FF main_sel_op_lt{}; - FF main_sel_op_lte{}; - FF main_sel_op_mov{}; - FF main_sel_op_mul{}; - FF main_sel_op_not{}; - FF main_sel_op_note_hash_exists{}; - FF main_sel_op_nullifier_exists{}; - FF main_sel_op_or{}; - FF main_sel_op_pedersen{}; - FF main_sel_op_poseidon2{}; - FF main_sel_op_radix_le{}; - FF main_sel_op_sender{}; - FF main_sel_op_sha256{}; - FF main_sel_op_shl{}; - FF main_sel_op_shr{}; - FF main_sel_op_sload{}; - FF main_sel_op_sstore{}; - FF main_sel_op_storage_address{}; - FF main_sel_op_sub{}; - FF main_sel_op_timestamp{}; - FF main_sel_op_transaction_fee{}; - FF main_sel_op_version{}; - FF main_sel_op_xor{}; - FF main_sel_q_kernel_lookup{}; - FF main_sel_q_kernel_output_lookup{}; - FF main_sel_resolve_ind_addr_a{}; - FF main_sel_resolve_ind_addr_b{}; - FF main_sel_resolve_ind_addr_c{}; - FF main_sel_resolve_ind_addr_d{}; - FF main_sel_rng_16{}; - FF main_sel_rng_8{}; - FF main_space_id{}; - FF main_tag_err{}; - FF main_w_in_tag{}; - FF mem_addr{}; - FF mem_clk{}; - FF mem_diff_hi{}; - FF mem_diff_lo{}; - FF mem_diff_mid{}; - FF mem_glob_addr{}; - FF mem_last{}; - FF mem_lastAccess{}; - FF mem_one_min_inv{}; - FF mem_r_in_tag{}; - FF mem_rw{}; - FF mem_sel_mem{}; - FF mem_sel_mov_ia_to_ic{}; - FF mem_sel_mov_ib_to_ic{}; - FF mem_sel_op_a{}; - FF mem_sel_op_b{}; - FF mem_sel_op_c{}; - FF mem_sel_op_cmov{}; - FF mem_sel_op_d{}; - FF mem_sel_resolve_ind_addr_a{}; - FF mem_sel_resolve_ind_addr_b{}; - FF mem_sel_resolve_ind_addr_c{}; - FF mem_sel_resolve_ind_addr_d{}; - FF mem_sel_rng_chk{}; - FF mem_skip_check_tag{}; - FF mem_space_id{}; - FF mem_tag{}; - FF mem_tag_err{}; - FF mem_tsp{}; - FF mem_val{}; - FF mem_w_in_tag{}; - FF pedersen_clk{}; - FF pedersen_input{}; - FF pedersen_output{}; - FF pedersen_sel_pedersen{}; - FF poseidon2_clk{}; - FF poseidon2_input{}; - FF poseidon2_output{}; - FF poseidon2_sel_poseidon_perm{}; - FF powers_power_of_2{}; - FF sha256_clk{}; - FF sha256_input{}; - FF sha256_output{}; - FF sha256_sel_sha256_compression{}; - FF sha256_state{}; - FF perm_main_alu{}; - FF perm_main_bin{}; - FF perm_main_conv{}; - FF perm_main_pos2_perm{}; - FF perm_main_pedersen{}; - FF perm_main_mem_a{}; - FF perm_main_mem_b{}; - FF perm_main_mem_c{}; - FF perm_main_mem_d{}; - FF perm_main_mem_ind_addr_a{}; - FF perm_main_mem_ind_addr_b{}; - FF perm_main_mem_ind_addr_c{}; - FF perm_main_mem_ind_addr_d{}; - FF lookup_byte_lengths{}; - FF lookup_byte_operations{}; - FF lookup_opcode_gas{}; - FF range_check_l2_gas_hi{}; - FF range_check_l2_gas_lo{}; - FF range_check_da_gas_hi{}; - FF range_check_da_gas_lo{}; - FF kernel_output_lookup{}; - FF lookup_into_kernel{}; - FF incl_main_tag_err{}; - FF incl_mem_tag_err{}; - FF lookup_mem_rng_chk_lo{}; - FF lookup_mem_rng_chk_mid{}; - FF lookup_mem_rng_chk_hi{}; - FF lookup_pow_2_0{}; - FF lookup_pow_2_1{}; - FF lookup_u8_0{}; - FF lookup_u8_1{}; - FF lookup_u16_0{}; - FF lookup_u16_1{}; - FF lookup_u16_2{}; - FF lookup_u16_3{}; - FF lookup_u16_4{}; - FF lookup_u16_5{}; - FF lookup_u16_6{}; - FF lookup_u16_7{}; - FF lookup_u16_8{}; - FF lookup_u16_9{}; - FF lookup_u16_10{}; - FF lookup_u16_11{}; - FF lookup_u16_12{}; - FF lookup_u16_13{}; - FF lookup_u16_14{}; - FF lookup_div_u16_0{}; - FF lookup_div_u16_1{}; - FF lookup_div_u16_2{}; - FF lookup_div_u16_3{}; - FF lookup_div_u16_4{}; - FF lookup_div_u16_5{}; - FF lookup_div_u16_6{}; - FF lookup_div_u16_7{}; - FF lookup_byte_lengths_counts{}; - FF lookup_byte_operations_counts{}; - FF lookup_opcode_gas_counts{}; - FF range_check_l2_gas_hi_counts{}; - FF range_check_l2_gas_lo_counts{}; - FF range_check_da_gas_hi_counts{}; - FF range_check_da_gas_lo_counts{}; - FF kernel_output_lookup_counts{}; - FF lookup_into_kernel_counts{}; - FF incl_main_tag_err_counts{}; - FF incl_mem_tag_err_counts{}; - FF lookup_mem_rng_chk_lo_counts{}; - FF lookup_mem_rng_chk_mid_counts{}; - FF lookup_mem_rng_chk_hi_counts{}; - FF lookup_pow_2_0_counts{}; - FF lookup_pow_2_1_counts{}; - FF lookup_u8_0_counts{}; - FF lookup_u8_1_counts{}; - FF lookup_u16_0_counts{}; - FF lookup_u16_1_counts{}; - FF lookup_u16_2_counts{}; - FF lookup_u16_3_counts{}; - FF lookup_u16_4_counts{}; - FF lookup_u16_5_counts{}; - FF lookup_u16_6_counts{}; - FF lookup_u16_7_counts{}; - FF lookup_u16_8_counts{}; - FF lookup_u16_9_counts{}; - FF lookup_u16_10_counts{}; - FF lookup_u16_11_counts{}; - FF lookup_u16_12_counts{}; - FF lookup_u16_13_counts{}; - FF lookup_u16_14_counts{}; - FF lookup_div_u16_0_counts{}; - FF lookup_div_u16_1_counts{}; - FF lookup_div_u16_2_counts{}; - FF lookup_div_u16_3_counts{}; - FF lookup_div_u16_4_counts{}; - FF lookup_div_u16_5_counts{}; - FF lookup_div_u16_6_counts{}; - FF lookup_div_u16_7_counts{}; - - [[maybe_unused]] static std::vector names(); -}; - -template std::ostream& operator<<(std::ostream& os, AvmFullRow const& row); - class AvmCircuitBuilder { public: using Flavor = bb::AvmFlavor; diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp index fedb4c60bcd..a2a58cd49a4 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor.hpp @@ -12,6 +12,8 @@ #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/transcript/transcript.hpp" +#include "barretenberg/vm/generated/avm_flavor_settings.hpp" + // Relations #include "barretenberg/relations/generated/avm/alu.hpp" #include "barretenberg/relations/generated/avm/binary.hpp" @@ -90,19 +92,19 @@ namespace bb { class AvmFlavor { public: - using Curve = curve::BN254; - using G1 = Curve::Group; - using PCS = KZG; + using Curve = AvmFlavorSettings::Curve; + using G1 = AvmFlavorSettings::G1; + using PCS = AvmFlavorSettings::PCS; - 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; + using FF = AvmFlavorSettings::FF; + using Polynomial = AvmFlavorSettings::Polynomial; + using PolynomialHandle = AvmFlavorSettings::PolynomialHandle; + using GroupElement = AvmFlavorSettings::GroupElement; + using Commitment = AvmFlavorSettings::Commitment; + using CommitmentHandle = AvmFlavorSettings::CommitmentHandle; + using CommitmentKey = AvmFlavorSettings::CommitmentKey; + using VerifierCommitmentKey = AvmFlavorSettings::VerifierCommitmentKey; + using RelationSeparator = AvmFlavorSettings::RelationSeparator; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 2; static constexpr size_t NUM_WITNESS_ENTITIES = 385; diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor_settings.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor_settings.hpp new file mode 100644 index 00000000000..d901afcc8b4 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_flavor_settings.hpp @@ -0,0 +1,28 @@ +#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" + +namespace bb { + +class AvmFlavorSettings { + public: + 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; +}; + +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_full_row.cpp similarity index 99% rename from barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp rename to barretenberg/cpp/src/barretenberg/vm/generated/avm_full_row.cpp index a3edcb9c1a0..3cda79780a3 100644 --- a/barretenberg/cpp/src/barretenberg/vm/generated/avm_circuit_builder.cpp +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_full_row.cpp @@ -1,4 +1,5 @@ -#include "barretenberg/vm/generated/avm_circuit_builder.hpp" +#include "barretenberg/vm/generated/avm_full_row.hpp" +#include "barretenberg/vm/generated/avm_flavor_settings.hpp" namespace bb { namespace { @@ -799,7 +800,7 @@ template std::ostream& operator<<(std::ostream& os, AvmFullRow } // Explicit template instantiation. -template std::ostream& operator<<(std::ostream& os, AvmFullRow const& row); -template std::vector AvmFullRow::names(); +template std::ostream& operator<<(std::ostream& os, AvmFullRow const& row); +template std::vector AvmFullRow::names(); } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/vm/generated/avm_full_row.hpp b/barretenberg/cpp/src/barretenberg/vm/generated/avm_full_row.hpp new file mode 100644 index 00000000000..6499381c181 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/vm/generated/avm_full_row.hpp @@ -0,0 +1,403 @@ +#pragma once + +#include +#include +#include + +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 main_calldata{}; + FF alu_a_hi{}; + FF alu_a_lo{}; + FF alu_b_hi{}; + FF alu_b_lo{}; + FF alu_borrow{}; + FF alu_cf{}; + FF alu_clk{}; + FF alu_cmp_rng_ctr{}; + FF alu_div_u16_r0{}; + FF alu_div_u16_r1{}; + FF alu_div_u16_r2{}; + FF alu_div_u16_r3{}; + FF alu_div_u16_r4{}; + FF alu_div_u16_r5{}; + FF alu_div_u16_r6{}; + FF alu_div_u16_r7{}; + FF alu_divisor_hi{}; + FF alu_divisor_lo{}; + FF alu_ff_tag{}; + FF alu_ia{}; + FF alu_ib{}; + FF alu_ic{}; + FF alu_in_tag{}; + FF alu_op_add{}; + FF alu_op_cast{}; + FF alu_op_cast_prev{}; + FF alu_op_div{}; + FF alu_op_div_a_lt_b{}; + FF alu_op_div_std{}; + FF alu_op_eq{}; + FF alu_op_eq_diff_inv{}; + FF alu_op_lt{}; + FF alu_op_lte{}; + FF alu_op_mul{}; + FF alu_op_not{}; + FF alu_op_shl{}; + FF alu_op_shr{}; + FF alu_op_sub{}; + FF alu_p_a_borrow{}; + FF alu_p_b_borrow{}; + FF alu_p_sub_a_hi{}; + FF alu_p_sub_a_lo{}; + FF alu_p_sub_b_hi{}; + FF alu_p_sub_b_lo{}; + FF alu_partial_prod_hi{}; + FF alu_partial_prod_lo{}; + FF alu_quotient_hi{}; + FF alu_quotient_lo{}; + FF alu_remainder{}; + FF alu_res_hi{}; + FF alu_res_lo{}; + FF alu_sel_alu{}; + FF alu_sel_cmp{}; + FF alu_sel_div_rng_chk{}; + FF alu_sel_rng_chk{}; + FF alu_sel_rng_chk_lookup{}; + FF alu_sel_shift_which{}; + FF alu_shift_lt_bit_len{}; + FF alu_t_sub_s_bits{}; + FF alu_two_pow_s{}; + FF alu_two_pow_t_sub_s{}; + FF alu_u128_tag{}; + FF alu_u16_r0{}; + FF alu_u16_r1{}; + FF alu_u16_r10{}; + FF alu_u16_r11{}; + FF alu_u16_r12{}; + FF alu_u16_r13{}; + FF alu_u16_r14{}; + FF alu_u16_r2{}; + FF alu_u16_r3{}; + FF alu_u16_r4{}; + FF alu_u16_r5{}; + FF alu_u16_r6{}; + FF alu_u16_r7{}; + FF alu_u16_r8{}; + FF alu_u16_r9{}; + FF alu_u16_tag{}; + FF alu_u32_tag{}; + FF alu_u64_tag{}; + FF alu_u8_r0{}; + FF alu_u8_r1{}; + FF alu_u8_tag{}; + FF binary_acc_ia{}; + FF binary_acc_ib{}; + FF binary_acc_ic{}; + FF binary_clk{}; + FF binary_ia_bytes{}; + FF binary_ib_bytes{}; + FF binary_ic_bytes{}; + FF binary_in_tag{}; + FF binary_mem_tag_ctr{}; + FF binary_mem_tag_ctr_inv{}; + FF binary_op_id{}; + FF binary_sel_bin{}; + FF binary_start{}; + FF byte_lookup_sel_bin{}; + FF byte_lookup_table_byte_lengths{}; + FF byte_lookup_table_in_tags{}; + FF byte_lookup_table_input_a{}; + FF byte_lookup_table_input_b{}; + FF byte_lookup_table_op_id{}; + FF byte_lookup_table_output{}; + FF conversion_clk{}; + FF conversion_input{}; + FF conversion_num_limbs{}; + FF conversion_radix{}; + FF conversion_sel_to_radix_le{}; + FF gas_da_gas_fixed_table{}; + FF gas_l2_gas_fixed_table{}; + FF gas_sel_gas_cost{}; + FF keccakf1600_clk{}; + FF keccakf1600_input{}; + FF keccakf1600_output{}; + FF keccakf1600_sel_keccakf1600{}; + FF kernel_emit_l2_to_l1_msg_write_offset{}; + FF kernel_emit_note_hash_write_offset{}; + FF kernel_emit_nullifier_write_offset{}; + FF kernel_emit_unencrypted_log_write_offset{}; + FF kernel_kernel_in_offset{}; + FF kernel_kernel_out_offset{}; + FF kernel_l1_to_l2_msg_exists_write_offset{}; + FF kernel_note_hash_exist_write_offset{}; + FF kernel_nullifier_exists_write_offset{}; + FF kernel_nullifier_non_exists_write_offset{}; + FF kernel_q_public_input_kernel_add_to_table{}; + FF kernel_q_public_input_kernel_out_add_to_table{}; + FF kernel_side_effect_counter{}; + FF kernel_sload_write_offset{}; + FF kernel_sstore_write_offset{}; + FF main_abs_da_rem_gas_hi{}; + FF main_abs_da_rem_gas_lo{}; + FF main_abs_l2_rem_gas_hi{}; + FF main_abs_l2_rem_gas_lo{}; + FF main_alu_in_tag{}; + FF main_bin_op_id{}; + FF main_call_ptr{}; + FF main_da_gas_op_cost{}; + FF main_da_gas_remaining{}; + FF main_da_out_of_gas{}; + FF main_ia{}; + FF main_ib{}; + FF main_ic{}; + FF main_id{}; + FF main_id_zero{}; + FF main_ind_addr_a{}; + FF main_ind_addr_b{}; + FF main_ind_addr_c{}; + FF main_ind_addr_d{}; + FF main_internal_return_ptr{}; + FF main_inv{}; + FF main_l2_gas_op_cost{}; + FF main_l2_gas_remaining{}; + FF main_l2_out_of_gas{}; + FF main_mem_addr_a{}; + FF main_mem_addr_b{}; + FF main_mem_addr_c{}; + FF main_mem_addr_d{}; + FF main_op_err{}; + FF main_opcode_val{}; + FF main_pc{}; + FF main_r_in_tag{}; + FF main_rwa{}; + FF main_rwb{}; + FF main_rwc{}; + FF main_rwd{}; + FF main_sel_alu{}; + FF main_sel_bin{}; + FF main_sel_gas_accounting_active{}; + FF main_sel_last{}; + FF main_sel_mem_op_a{}; + FF main_sel_mem_op_activate_gas{}; + FF main_sel_mem_op_b{}; + FF main_sel_mem_op_c{}; + FF main_sel_mem_op_d{}; + FF main_sel_mov_ia_to_ic{}; + FF main_sel_mov_ib_to_ic{}; + FF main_sel_op_add{}; + FF main_sel_op_address{}; + FF main_sel_op_and{}; + FF main_sel_op_block_number{}; + FF main_sel_op_cast{}; + FF main_sel_op_chain_id{}; + FF main_sel_op_cmov{}; + FF main_sel_op_coinbase{}; + FF main_sel_op_dagasleft{}; + FF main_sel_op_div{}; + FF main_sel_op_emit_l2_to_l1_msg{}; + FF main_sel_op_emit_note_hash{}; + FF main_sel_op_emit_nullifier{}; + FF main_sel_op_emit_unencrypted_log{}; + FF main_sel_op_eq{}; + FF main_sel_op_external_call{}; + FF main_sel_op_fdiv{}; + FF main_sel_op_fee_per_da_gas{}; + FF main_sel_op_fee_per_l2_gas{}; + FF main_sel_op_function_selector{}; + FF main_sel_op_get_contract_instance{}; + FF main_sel_op_halt{}; + FF main_sel_op_internal_call{}; + FF main_sel_op_internal_return{}; + FF main_sel_op_jump{}; + FF main_sel_op_jumpi{}; + FF main_sel_op_keccak{}; + FF main_sel_op_l1_to_l2_msg_exists{}; + FF main_sel_op_l2gasleft{}; + FF main_sel_op_lt{}; + FF main_sel_op_lte{}; + FF main_sel_op_mov{}; + FF main_sel_op_mul{}; + FF main_sel_op_not{}; + FF main_sel_op_note_hash_exists{}; + FF main_sel_op_nullifier_exists{}; + FF main_sel_op_or{}; + FF main_sel_op_pedersen{}; + FF main_sel_op_poseidon2{}; + FF main_sel_op_radix_le{}; + FF main_sel_op_sender{}; + FF main_sel_op_sha256{}; + FF main_sel_op_shl{}; + FF main_sel_op_shr{}; + FF main_sel_op_sload{}; + FF main_sel_op_sstore{}; + FF main_sel_op_storage_address{}; + FF main_sel_op_sub{}; + FF main_sel_op_timestamp{}; + FF main_sel_op_transaction_fee{}; + FF main_sel_op_version{}; + FF main_sel_op_xor{}; + FF main_sel_q_kernel_lookup{}; + FF main_sel_q_kernel_output_lookup{}; + FF main_sel_resolve_ind_addr_a{}; + FF main_sel_resolve_ind_addr_b{}; + FF main_sel_resolve_ind_addr_c{}; + FF main_sel_resolve_ind_addr_d{}; + FF main_sel_rng_16{}; + FF main_sel_rng_8{}; + FF main_space_id{}; + FF main_tag_err{}; + FF main_w_in_tag{}; + FF mem_addr{}; + FF mem_clk{}; + FF mem_diff_hi{}; + FF mem_diff_lo{}; + FF mem_diff_mid{}; + FF mem_glob_addr{}; + FF mem_last{}; + FF mem_lastAccess{}; + FF mem_one_min_inv{}; + FF mem_r_in_tag{}; + FF mem_rw{}; + FF mem_sel_mem{}; + FF mem_sel_mov_ia_to_ic{}; + FF mem_sel_mov_ib_to_ic{}; + FF mem_sel_op_a{}; + FF mem_sel_op_b{}; + FF mem_sel_op_c{}; + FF mem_sel_op_cmov{}; + FF mem_sel_op_d{}; + FF mem_sel_resolve_ind_addr_a{}; + FF mem_sel_resolve_ind_addr_b{}; + FF mem_sel_resolve_ind_addr_c{}; + FF mem_sel_resolve_ind_addr_d{}; + FF mem_sel_rng_chk{}; + FF mem_skip_check_tag{}; + FF mem_space_id{}; + FF mem_tag{}; + FF mem_tag_err{}; + FF mem_tsp{}; + FF mem_val{}; + FF mem_w_in_tag{}; + FF pedersen_clk{}; + FF pedersen_input{}; + FF pedersen_output{}; + FF pedersen_sel_pedersen{}; + FF poseidon2_clk{}; + FF poseidon2_input{}; + FF poseidon2_output{}; + FF poseidon2_sel_poseidon_perm{}; + FF powers_power_of_2{}; + FF sha256_clk{}; + FF sha256_input{}; + FF sha256_output{}; + FF sha256_sel_sha256_compression{}; + FF sha256_state{}; + FF perm_main_alu{}; + FF perm_main_bin{}; + FF perm_main_conv{}; + FF perm_main_pos2_perm{}; + FF perm_main_pedersen{}; + FF perm_main_mem_a{}; + FF perm_main_mem_b{}; + FF perm_main_mem_c{}; + FF perm_main_mem_d{}; + FF perm_main_mem_ind_addr_a{}; + FF perm_main_mem_ind_addr_b{}; + FF perm_main_mem_ind_addr_c{}; + FF perm_main_mem_ind_addr_d{}; + FF lookup_byte_lengths{}; + FF lookup_byte_operations{}; + FF lookup_opcode_gas{}; + FF range_check_l2_gas_hi{}; + FF range_check_l2_gas_lo{}; + FF range_check_da_gas_hi{}; + FF range_check_da_gas_lo{}; + FF kernel_output_lookup{}; + FF lookup_into_kernel{}; + FF incl_main_tag_err{}; + FF incl_mem_tag_err{}; + FF lookup_mem_rng_chk_lo{}; + FF lookup_mem_rng_chk_mid{}; + FF lookup_mem_rng_chk_hi{}; + FF lookup_pow_2_0{}; + FF lookup_pow_2_1{}; + FF lookup_u8_0{}; + FF lookup_u8_1{}; + FF lookup_u16_0{}; + FF lookup_u16_1{}; + FF lookup_u16_2{}; + FF lookup_u16_3{}; + FF lookup_u16_4{}; + FF lookup_u16_5{}; + FF lookup_u16_6{}; + FF lookup_u16_7{}; + FF lookup_u16_8{}; + FF lookup_u16_9{}; + FF lookup_u16_10{}; + FF lookup_u16_11{}; + FF lookup_u16_12{}; + FF lookup_u16_13{}; + FF lookup_u16_14{}; + FF lookup_div_u16_0{}; + FF lookup_div_u16_1{}; + FF lookup_div_u16_2{}; + FF lookup_div_u16_3{}; + FF lookup_div_u16_4{}; + FF lookup_div_u16_5{}; + FF lookup_div_u16_6{}; + FF lookup_div_u16_7{}; + FF lookup_byte_lengths_counts{}; + FF lookup_byte_operations_counts{}; + FF lookup_opcode_gas_counts{}; + FF range_check_l2_gas_hi_counts{}; + FF range_check_l2_gas_lo_counts{}; + FF range_check_da_gas_hi_counts{}; + FF range_check_da_gas_lo_counts{}; + FF kernel_output_lookup_counts{}; + FF lookup_into_kernel_counts{}; + FF incl_main_tag_err_counts{}; + FF incl_mem_tag_err_counts{}; + FF lookup_mem_rng_chk_lo_counts{}; + FF lookup_mem_rng_chk_mid_counts{}; + FF lookup_mem_rng_chk_hi_counts{}; + FF lookup_pow_2_0_counts{}; + FF lookup_pow_2_1_counts{}; + FF lookup_u8_0_counts{}; + FF lookup_u8_1_counts{}; + FF lookup_u16_0_counts{}; + FF lookup_u16_1_counts{}; + FF lookup_u16_2_counts{}; + FF lookup_u16_3_counts{}; + FF lookup_u16_4_counts{}; + FF lookup_u16_5_counts{}; + FF lookup_u16_6_counts{}; + FF lookup_u16_7_counts{}; + FF lookup_u16_8_counts{}; + FF lookup_u16_9_counts{}; + FF lookup_u16_10_counts{}; + FF lookup_u16_11_counts{}; + FF lookup_u16_12_counts{}; + FF lookup_u16_13_counts{}; + FF lookup_u16_14_counts{}; + FF lookup_div_u16_0_counts{}; + FF lookup_div_u16_1_counts{}; + FF lookup_div_u16_2_counts{}; + FF lookup_div_u16_3_counts{}; + FF lookup_div_u16_4_counts{}; + FF lookup_div_u16_5_counts{}; + FF lookup_div_u16_6_counts{}; + FF lookup_div_u16_7_counts{}; + + [[maybe_unused]] static std::vector names(); +}; + +template std::ostream& operator<<(std::ostream& os, AvmFullRow const& row); + +} // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp index 0640121b319..e2c80155ada 100644 --- a/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp +++ b/barretenberg/cpp/src/barretenberg/vm/tests/helpers.test.hpp @@ -18,8 +18,7 @@ namespace tests_avm { -using Flavor = bb::AvmFlavor; -using FF = Flavor::FF; +using FF = bb::AvmFlavorSettings::FF; using Row = bb::AvmFullRow; using ThreeOpParam = std::array; using ThreeOpParamRow = std::tuple; diff --git a/bb-pilcom/bb-pil-backend/src/circuit_builder.rs b/bb-pilcom/bb-pil-backend/src/circuit_builder.rs index 3a575644ce7..2d42e542135 100644 --- a/bb-pilcom/bb-pil-backend/src/circuit_builder.rs +++ b/bb-pilcom/bb-pil-backend/src/circuit_builder.rs @@ -13,7 +13,8 @@ pub trait CircuitBuilder { to_be_shifted: &[String], ); - fn create_circuit_builder_cpp(&mut self, name: &str, all_cols: &[String]); + fn create_full_row_hpp(&mut self, name: &str, all_cols: &[String]); + fn create_full_row_cpp(&mut self, name: &str, all_cols: &[String]); } impl CircuitBuilder for BBFiles { @@ -54,7 +55,7 @@ impl CircuitBuilder for BBFiles { ); } - fn create_circuit_builder_cpp(&mut self, name: &str, all_cols: &[String]) { + fn create_full_row_hpp(&mut self, name: &str, all_cols: &[String]) { let mut handlebars = Handlebars::new(); let data = &json!({ @@ -64,18 +65,41 @@ impl CircuitBuilder for BBFiles { handlebars .register_template_string( - "circuit_builder.cpp", - std::str::from_utf8(include_bytes!("../templates/circuit_builder.cpp.hbs")) - .unwrap(), + "full_row.hpp", + std::str::from_utf8(include_bytes!("../templates/full_row.hpp.hbs")).unwrap(), + ) + .unwrap(); + + let hpp = handlebars.render("full_row.hpp", data).unwrap(); + + self.write_file( + &self.circuit, + &format!("{}_full_row.hpp", snake_case(name)), + &hpp, + ); + } + + fn create_full_row_cpp(&mut self, name: &str, all_cols: &[String]) { + let mut handlebars = Handlebars::new(); + + let data = &json!({ + "name": name, + "all_cols": all_cols, + }); + + handlebars + .register_template_string( + "full_row.cpp", + std::str::from_utf8(include_bytes!("../templates/full_row.cpp.hbs")).unwrap(), ) .unwrap(); - let circuit_cpp = handlebars.render("circuit_builder.cpp", data).unwrap(); + let cpp = handlebars.render("full_row.cpp", data).unwrap(); self.write_file( &self.circuit, - &format!("{}_circuit_builder.cpp", snake_case(name)), - &circuit_cpp, + &format!("{}_full_row.cpp", snake_case(name)), + &cpp, ); } } diff --git a/bb-pilcom/bb-pil-backend/src/flavor_builder.rs b/bb-pilcom/bb-pil-backend/src/flavor_builder.rs index f2e794970b7..535fbc1d094 100644 --- a/bb-pilcom/bb-pil-backend/src/flavor_builder.rs +++ b/bb-pilcom/bb-pil-backend/src/flavor_builder.rs @@ -17,6 +17,8 @@ pub trait FlavorBuilder { shifted: &[String], all_cols_and_shifts: &[String], ); + + fn create_flavor_settings_hpp(&mut self, name: &str); } /// Build the boilerplate for the flavor file @@ -64,4 +66,28 @@ impl FlavorBuilder for BBFiles { &flavor_hpp, ); } + + fn create_flavor_settings_hpp(&mut self, name: &str) { + let mut handlebars = Handlebars::new(); + + let data = &json!({ + "name": name, + }); + + handlebars + .register_template_string( + "flavor_settings.hpp", + std::str::from_utf8(include_bytes!("../templates/flavor_settings.hpp.hbs")) + .unwrap(), + ) + .unwrap(); + + let flavor_hpp = handlebars.render("flavor_settings.hpp", data).unwrap(); + + self.write_file( + &self.flavor, + &format!("{}_flavor_settings.hpp", snake_case(name)), + &flavor_hpp, + ); + } } diff --git a/bb-pilcom/bb-pil-backend/src/vm_builder.rs b/bb-pilcom/bb-pil-backend/src/vm_builder.rs index 264bd698c1a..2bee8ebcd1f 100644 --- a/bb-pilcom/bb-pil-backend/src/vm_builder.rs +++ b/bb-pilcom/bb-pil-backend/src/vm_builder.rs @@ -116,6 +116,10 @@ pub fn analyzed_to_cpp( bb_files.create_declare_views(file_name, &all_cols_with_shifts); + // ----------------------- Create the full row files ----------------------- + bb_files.create_full_row_hpp(file_name, &all_cols); + bb_files.create_full_row_cpp(file_name, &all_cols); + // ----------------------- Create the circuit builder file ----------------------- bb_files.create_circuit_builder_hpp( file_name, @@ -126,8 +130,6 @@ pub fn analyzed_to_cpp( &to_be_shifted, ); - bb_files.create_circuit_builder_cpp(file_name, &all_cols); - // ----------------------- Create the flavor file ----------------------- bb_files.create_flavor_hpp( file_name, @@ -142,6 +144,8 @@ pub fn analyzed_to_cpp( &all_cols_with_shifts, ); + bb_files.create_flavor_settings_hpp(file_name); + // ----------------------- Create the composer files ----------------------- bb_files.create_composer_cpp(file_name); bb_files.create_composer_hpp(file_name); diff --git a/bb-pilcom/bb-pil-backend/templates/circuit_builder.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/circuit_builder.hpp.hbs index 53adc31a0cc..ed14f5dab71 100644 --- a/bb-pilcom/bb-pil-backend/templates/circuit_builder.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/circuit_builder.hpp.hbs @@ -14,22 +14,11 @@ #include "barretenberg/relations/generic_lookup/generic_lookup_relation.hpp" #include "barretenberg/honk/proof_system/logderivative_library.hpp" -// This already imports the relations and permutations. For now we rely on the transitive includes. +#include "barretenberg/vm/generated/{{snakeCase name}}_full_row.hpp" #include "barretenberg/vm/generated/{{snakeCase name}}_flavor.hpp" namespace bb { -template -struct {{name}}FullRow { - {{#each all_cols as |col|}} - FF {{col}}{}; - {{/each}} - - [[maybe_unused]] static std::vector names(); -}; - -template std::ostream& operator<<(std::ostream& os, {{name}}FullRow const& row); - class {{name}}CircuitBuilder { public: using Flavor = bb::{{name}}Flavor; diff --git a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs index 6c879c84fb8..8b3ee2445db 100644 --- a/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/flavor.hpp.hbs @@ -12,6 +12,8 @@ #include "barretenberg/polynomials/polynomial.hpp" #include "barretenberg/flavor/flavor.hpp" +#include "barretenberg/vm/generated/{{snakeCase name}}_flavor_settings.hpp" + // Relations {{#each relation_file_names as |r|}} #include "barretenberg/relations/generated/{{snakeCase ../name}}/{{r}}.hpp" @@ -30,19 +32,19 @@ namespace bb { class {{name}}Flavor { public: - 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; + using Curve = {{name}}FlavorSettings::Curve; + using G1 = {{name}}FlavorSettings::G1; + using PCS = {{name}}FlavorSettings::PCS; + + using FF = {{name}}FlavorSettings::FF; + using Polynomial = {{name}}FlavorSettings::Polynomial; + using PolynomialHandle = {{name}}FlavorSettings::PolynomialHandle; + using GroupElement = {{name}}FlavorSettings::GroupElement; + using Commitment = {{name}}FlavorSettings::Commitment; + using CommitmentHandle = {{name}}FlavorSettings::CommitmentHandle; + using CommitmentKey = {{name}}FlavorSettings::CommitmentKey; + using VerifierCommitmentKey = {{name}}FlavorSettings::VerifierCommitmentKey; + using RelationSeparator = {{name}}FlavorSettings::RelationSeparator; static constexpr size_t NUM_PRECOMPUTED_ENTITIES = {{len fixed}}; static constexpr size_t NUM_WITNESS_ENTITIES = {{len witness}}; diff --git a/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs new file mode 100644 index 00000000000..b8d48acc71e --- /dev/null +++ b/bb-pilcom/bb-pil-backend/templates/flavor_settings.hpp.hbs @@ -0,0 +1,28 @@ +#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" + +namespace bb { + +class {{name}}FlavorSettings { + public: + 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; +}; + +} // namespace bb \ No newline at end of file diff --git a/bb-pilcom/bb-pil-backend/templates/circuit_builder.cpp.hbs b/bb-pilcom/bb-pil-backend/templates/full_row.cpp.hbs similarity index 77% rename from bb-pilcom/bb-pil-backend/templates/circuit_builder.cpp.hbs rename to bb-pilcom/bb-pil-backend/templates/full_row.cpp.hbs index 26dd5d3d514..8d02439b421 100644 --- a/bb-pilcom/bb-pil-backend/templates/circuit_builder.cpp.hbs +++ b/bb-pilcom/bb-pil-backend/templates/full_row.cpp.hbs @@ -1,4 +1,5 @@ -#include "barretenberg/vm/generated/{{snakeCase name}}_circuit_builder.hpp" +#include "barretenberg/vm/generated/{{snakeCase name}}_full_row.hpp" +#include "barretenberg/vm/generated/{{snakeCase name}}_flavor_settings.hpp" namespace bb { namespace { @@ -33,7 +34,7 @@ template std::ostream& operator<<(std::ostream& os, {{name}}FullRo } // Explicit template instantiation. -template std::ostream& operator<<(std::ostream& os, {{name}}FullRow const& row); -template std::vector {{name}}FullRow::names(); +template std::ostream& operator<<(std::ostream& os, {{name}}FullRow<{{name}}FlavorSettings::FF> const& row); +template std::vector {{name}}FullRow<{{name}}FlavorSettings::FF>::names(); } // namespace bb diff --git a/bb-pilcom/bb-pil-backend/templates/full_row.hpp.hbs b/bb-pilcom/bb-pil-backend/templates/full_row.hpp.hbs new file mode 100644 index 00000000000..17cddb17f25 --- /dev/null +++ b/bb-pilcom/bb-pil-backend/templates/full_row.hpp.hbs @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include + +namespace bb { + +template +struct {{name}}FullRow { + {{#each all_cols as |col|}} + FF {{col}}{}; + {{/each}} + + [[maybe_unused]] static std::vector names(); +}; + +template std::ostream& operator<<(std::ostream& os, {{name}}FullRow const& row); + +} // namespace bb \ No newline at end of file