Skip to content

Commit

Permalink
feat(avm): include bb-pilcom in monorepo (#7098)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 authored Jun 20, 2024
1 parent 7bd7c66 commit 0442158
Show file tree
Hide file tree
Showing 41 changed files with 6,206 additions and 659 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions barretenberg/cpp/pil/avm/kernel.pil
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 1 addition & 20 deletions barretenberg/cpp/scripts/compile_avm.sh
Original file line number Diff line number Diff line change
@@ -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
../../bb-pilcom/target/release/bb_pil pil/avm/main.pil --name Avm
11 changes: 11 additions & 0 deletions barretenberg/cpp/scripts/rebuild_avm.sh
Original file line number Diff line number Diff line change
@@ -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
406 changes: 219 additions & 187 deletions barretenberg/cpp/src/barretenberg/relations/generated/avm/alu.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -69,81 +69,85 @@ template <typename FF_> 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;
}
// Contribution 1
{
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;
}
// Contribution 2
{
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;
}
// Contribution 3
{
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;
}
// Contribution 4
{
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;
}
// Contribution 5
{
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;
}
// Contribution 6
{
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;
}
// Contribution 7
{
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;
}
// Contribution 8
{
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;
}
// Contribution 9
{
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ template <typename FF_> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand Down Expand Up @@ -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); \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ template <typename FF_> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,31 @@ template <typename FF_> 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;
}
// Contribution 1
{
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;
}
// Contribution 2
{
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;
}
Expand All @@ -127,66 +131,74 @@ template <typename FF_> 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;
}
// Contribution 4
{
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;
}
// Contribution 5
{
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;
}
// Contribution 6
{
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;
}
// Contribution 7
{
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;
}
// Contribution 8
{
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;
}
// Contribution 9
{
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;
}
Expand Down
Loading

0 comments on commit 0442158

Please sign in to comment.