Skip to content
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: 10 additions & 1 deletion barretenberg/cpp/pil/avm/avm_main.pil
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include "avm_kernel.pil";
include "gadgets/avm_conversion.pil";
include "gadgets/avm_sha256.pil";
include "gadgets/avm_poseidon2.pil";
include "gadgets/avm_keccakf1600.pil";

namespace avm_main(256);
//===== CONSTANT POLYNOMIALS ==================================================
Expand Down Expand Up @@ -52,6 +53,7 @@ namespace avm_main(256);
pol commit sel_op_radix_le;
pol commit sel_op_sha256;
pol commit sel_op_poseidon2;
pol commit sel_op_keccak;

//===== Fix Range Checks Selectors=============================================
// We re-use the clk column for the lookup values of 8-bit resp. 16-bit range check.
Expand Down Expand Up @@ -208,6 +210,7 @@ namespace avm_main(256);
sel_op_radix_le * (1 - sel_op_radix_le) = 0;
sel_op_sha256 * (1 - sel_op_sha256) = 0;
sel_op_poseidon2 * (1 - sel_op_poseidon2) = 0;
sel_op_keccak * (1 - sel_op_keccak) = 0;

sel_op_add * (1 - sel_op_add) = 0;
sel_op_sub * (1 - sel_op_sub) = 0;
Expand Down Expand Up @@ -361,7 +364,7 @@ namespace avm_main(256);
//===== CONTROL_FLOW_CONSISTENCY ============================================
pol INTERNAL_CALL_STACK_SELECTORS = (first + sel_internal_call + sel_internal_return + sel_halt);
pol ALL_BINARY_SEL = sel_op_and + sel_op_or + sel_op_xor;
pol ALL_GADGET_SEL = sel_op_radix_le + sel_op_sha256 + sel_op_poseidon2;
pol ALL_GADGET_SEL = sel_op_radix_le + sel_op_sha256 + sel_op_poseidon2 + sel_op_keccak;
pol ALL_MEMORY_SEL = sel_cmov + sel_mov;
pol OPCODE_SELECTORS = ALU_ALL_SEL + ALL_BINARY_SEL + ALL_MEMORY_SEL + ALL_GADGET_SEL + KERNEL_INPUT_SELECTORS + KERNEL_OUTPUT_SELECTORS;

Expand Down Expand Up @@ -567,6 +570,12 @@ namespace avm_main(256);
is
avm_poseidon2.poseidon_perm_sel {avm_poseidon2.clk, avm_poseidon2.input, avm_poseidon2.output};

// This will be enabled when we migrate just to keccakf1600, as getting keccak to work with it is tricky.
// #[PERM_MAIN_KECCAK]
// sel_op_keccak {clk, ia, ic}
// is
// avm_keccakf1600.keccakf1600_sel {avm_keccakf1600.clk, avm_keccakf1600.input, avm_keccakf1600.output};

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

namespace avm_keccakf1600(256);

pol commit clk;

// Selector for Keccak Permutation Operation
pol commit keccakf1600_sel;
keccakf1600_sel * (1 - keccakf1600_sel) = 0;

// These will all be arrays, but we just store the first element for permutation to the main trace for now
pol commit input;
pol commit output;
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_keccakf1600Row {
FF avm_keccakf1600_keccakf1600_sel{};
};

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

template <typename FF_> class avm_keccakf1600Impl {
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_keccakf1600_keccakf1600_sel * (-avm_keccakf1600_keccakf1600_sel + FF(1)));
tmp *= scaling_factor;
std::get<0>(evals) += tmp;
}
}
};

template <typename FF> using avm_keccakf1600 = Relation<avm_keccakf1600Impl<FF>>;

} // namespace bb::Avm_vm
Loading