Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(avm): include bb-pilcom in monorepo #7098

Merged
merged 15 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the fork, public polynomials have been made a first class citizen, so we can call get_in_source_order for them, which means we will not have ordering issues anymore


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this (tests) should be here, or even if this script(s) is needed. But don't mind!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really just for convinience, but yes not required

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_bin_sel * (-binary_bin_sel + FF(1)));
auto tmp = ((binary_bin_sel * (-binary_bin_sel + 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_bin_sel + FF(1)) * (-binary_mem_tag_ctr_inv + FF(1))) + binary_mem_tag_ctr_inv)) -
binary_bin_sel);
auto tmp = (((binary_mem_tag_ctr *
(((-binary_bin_sel + FF(1)) * (-binary_mem_tag_ctr_inv + FF(1))) + binary_mem_tag_ctr_inv)) -
binary_bin_sel) -
FF(0));
tmp *= scaling_factor;
std::get<3>(evals) += tmp;
}
// Contribution 4
{
Avm_DECLARE_VIEWS(4);

auto tmp = ((-binary_bin_sel + FF(1)) * binary_acc_ia);
auto tmp = (((-binary_bin_sel + FF(1)) * binary_acc_ia) - FF(0));
tmp *= scaling_factor;
std::get<4>(evals) += tmp;
}
// Contribution 5
{
Avm_DECLARE_VIEWS(5);

auto tmp = ((-binary_bin_sel + FF(1)) * binary_acc_ib);
auto tmp = (((-binary_bin_sel + FF(1)) * binary_acc_ib) - FF(0));
tmp *= scaling_factor;
std::get<5>(evals) += tmp;
}
// Contribution 6
{
Avm_DECLARE_VIEWS(6);

auto tmp = ((-binary_bin_sel + FF(1)) * binary_acc_ic);
auto tmp = (((-binary_bin_sel + 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_to_radix_le_sel * (-conversion_to_radix_le_sel + FF(1)));
auto tmp = ((conversion_to_radix_le_sel * (-conversion_to_radix_le_sel + 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_first = View(new_term.main_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_alu_sel = View(new_term.alu_alu_sel); \
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_keccakf1600_sel * (-keccakf1600_keccakf1600_sel + FF(1)));
auto tmp = ((keccakf1600_keccakf1600_sel * (-keccakf1600_keccakf1600_sel + 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 @@ -97,27 +97,31 @@ template <typename FF_> class kernelImpl {
{
Avm_DECLARE_VIEWS(0);

auto tmp = ((-main_last + FF(1)) * (kernel_note_hash_exist_write_offset_shift -
(kernel_note_hash_exist_write_offset + main_sel_op_note_hash_exists)));
auto tmp =
(((-main_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_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_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_last + FF(1)) *
(kernel_nullifier_exists_write_offset_shift -
(kernel_nullifier_exists_write_offset + (main_sel_op_nullifier_exists * main_ib))));
auto tmp = (((-main_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 @@ -126,38 +130,42 @@ template <typename FF_> class kernelImpl {
Avm_DECLARE_VIEWS(3);

auto tmp =
((-main_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_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_last + FF(1)) * (kernel_emit_nullifier_write_offset_shift -
(kernel_emit_nullifier_write_offset + main_sel_op_emit_nullifier)));
auto tmp = (((-main_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_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_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_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_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;
}
Expand All @@ -166,26 +174,29 @@ template <typename FF_> class kernelImpl {
Avm_DECLARE_VIEWS(7);

auto tmp =
((-main_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)));
(((-main_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_last + FF(1)) *
(kernel_sload_write_offset_shift - (kernel_sload_write_offset + main_sel_op_sload)));
auto tmp = (((-main_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_last + FF(1)) *
(kernel_sstore_write_offset_shift - (kernel_sstore_write_offset + main_sel_op_sstore)));
auto tmp = (((-main_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
Loading