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): to_radix gadget #6368

Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 11 additions & 0 deletions barretenberg/cpp/pil/avm/avm_main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include "avm_mem.pil";
include "avm_alu.pil";
include "avm_binary.pil";
include "avm_kernel.pil";
include "gadgets/avm_conversion.pil";

namespace avm_main(256);
// Kernel lookup selector opcodes
Expand All @@ -25,6 +26,9 @@ namespace avm_main(256);
pol commit sel_op_coinbase;
pol commit sel_op_timestamp;

//===== Gadget Selectors ======================================================
pol commit sel_op_radix_le;

//===== CONSTANT POLYNOMIALS ==================================================
pol constant clk(i) { i };
pol constant first = [1] + [0]*; // Used mostly to toggle off the first row consisting
Expand Down Expand Up @@ -167,6 +171,8 @@ namespace avm_main(256);
sel_op_fee_per_da_gas * (1 - sel_op_fee_per_da_gas) = 0;
sel_op_transaction_fee * (1 - sel_op_transaction_fee) = 0;

sel_op_radix_le * (1 - sel_op_radix_le) = 0;

sel_op_add * (1 - sel_op_add) = 0;
sel_op_sub * (1 - sel_op_sub) = 0;
sel_op_mul * (1 - sel_op_mul) = 0;
Expand Down Expand Up @@ -451,6 +457,11 @@ namespace avm_main(256);
is
avm_binary.start {avm_binary.clk, avm_binary.acc_ia, avm_binary.acc_ib, avm_binary.acc_ic, avm_binary.op_id, avm_binary.in_tag};

#[PERM_MAIN_CONV]
sel_op_radix_le {clk, ia, ic, id}
is
avm_conversion.to_radix_le_sel {avm_conversion.clk, avm_conversion.input, avm_conversion.radix, avm_conversion.num_limbs};

#[PERM_MAIN_MEM_A]
mem_op_a {clk, mem_idx_a, ia, rwa
, r_in_tag, w_in_tag, sel_mov_a, sel_cmov}
Expand Down
21 changes: 21 additions & 0 deletions barretenberg/cpp/pil/avm/gadgets/avm_conversion.pil
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
include "../avm_main.pil";

namespace avm_conversion(256);

pol commit clk;

// Selector for Radix Operation
pol commit to_radix_le_sel;
to_radix_le_sel * (1 - to_radix_le_sel) = 0;

// ===== DRAFT: Planned Constraints for To Radix LE
// Similar to the binary trace; multi-row decomposition of the input using the number of limbs specified as the row count.
// (1) limb_ctr' - limb_ctr + 1 = 0; // Next row decrements the limb_ctr
// (2) Check equality to 0 of limb_ctr to terminate the operations.
// (3) An accumulation column to track the partial re-composition of the limbs
// (4) Range check each row.limb < radix
// (5) TODO: Is there a risk of over/under flow.

pol commit input;
pol commit radix;
pol commit num_limbs;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#pragma once
#include "../../relation_parameters.hpp"
#include "../../relation_types.hpp"
#include "./declare_views.hpp"

namespace bb::Avm_vm {

template <typename FF> struct Avm_conversionRow {
FF avm_conversion_to_radix_le_sel{};
};

inline std::string get_relation_label_avm_conversion(int index)
{
switch (index) {}
return std::to_string(index);
}

template <typename FF_> class avm_conversionImpl {
public:
using FF = FF_;

static constexpr std::array<size_t, 1> SUBRELATION_PARTIAL_LENGTHS{
3,
};

template <typename ContainerOverSubrelations, typename AllEntities>
void static accumulate(ContainerOverSubrelations& evals,
const AllEntities& new_term,
[[maybe_unused]] const RelationParameters<FF>&,
[[maybe_unused]] const FF& scaling_factor)
{

// Contribution 0
{
Avm_DECLARE_VIEWS(0);

auto tmp = (avm_conversion_to_radix_le_sel * (-avm_conversion_to_radix_le_sel + FF(1)));
tmp *= scaling_factor;
std::get<0>(evals) += tmp;
}
}
};

template <typename FF> using avm_conversion = Relation<avm_conversionImpl<FF>>;

} // namespace bb::Avm_vm
Loading
Loading