Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ TARGET=${1:-"bb"}
#FLOW=${2:-"ecdsar1+transfer_1_recursions+sponsored_fpc"}
#FLOW=${2:-"ecdsar1+transfer_1_recursions+sponsored_fpc"}
FLOW=${2:-"schnorr+deploy_tokenContract_with_registration+sponsored_fpc"}
BUILD_DIR="build-no-avm"
BUILD_DIR="build"

# Move above script dir.
cd $(dirname $0)/..
Expand Down
64 changes: 34 additions & 30 deletions barretenberg/cpp/src/barretenberg/honk/composer/permutation_lib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,50 +125,54 @@ PermutationMapping<Flavor::NUM_WIRES> compute_permutation_mapping(
const std::vector<CyclicPermutation>& wire_copy_cycles)
{

BB_BENCH_NAME("compute_permutation_mapping");

// Initialize the table of permutations so that every element points to itself
PermutationMapping<Flavor::NUM_WIRES> mapping(dyadic_size);

// Represents the idx of a variable in circuit_constructor.variables
std::span<const uint32_t> real_variable_tags = circuit_constructor.real_variable_tags;

// Go through each cycle
for (size_t cycle_idx = 0; cycle_idx < wire_copy_cycles.size(); ++cycle_idx) {
// We go through the cycle and fill-out/modify `mapping`. Following the generalized permutation algorithm, we
// take separate care of first/last node handling.
const CyclicPermutation& cycle = wire_copy_cycles[cycle_idx];
const auto cycle_size = cycle.size();
if (cycle_size == 0) {
continue;
}
parallel_for([&](const ThreadChunk& chunk) {
for (size_t cycle_idx : chunk.range(wire_copy_cycles.size())) {
// We go through the cycle and fill-out/modify `mapping`. Following the generalized permutation
// algorithm, we take separate care of first/last node handling.
const CyclicPermutation& cycle = wire_copy_cycles[cycle_idx];
const auto cycle_size = cycle.size();
if (cycle_size == 0) {
continue;
}

const cycle_node& first_node = cycle[0];
const cycle_node& last_node = cycle[cycle_size - 1];
const cycle_node& first_node = cycle[0];
const cycle_node& last_node = cycle[cycle_size - 1];

const auto first_row = static_cast<ptrdiff_t>(first_node.gate_idx);
const auto first_col = first_node.wire_idx;
const auto last_row = static_cast<ptrdiff_t>(last_node.gate_idx);
const auto last_col = last_node.wire_idx;
const auto first_row = static_cast<ptrdiff_t>(first_node.gate_idx);
const auto first_col = first_node.wire_idx;
const auto last_row = static_cast<ptrdiff_t>(last_node.gate_idx);
const auto last_col = last_node.wire_idx;

// First node: id gets tagged with the cycle's variable tag
mapping.ids[first_col].is_tag[first_row] = true;
mapping.ids[first_col].row_idx[first_row] = real_variable_tags[cycle_idx];
// First node: id gets tagged with the cycle's variable tag
mapping.ids[first_col].is_tag[first_row] = true;
mapping.ids[first_col].row_idx[first_row] = real_variable_tags[cycle_idx];

// Last node: sigma gets tagged and points to tau(tag) instead of wrapping to first node
mapping.sigmas[last_col].is_tag[last_row] = true;
mapping.sigmas[last_col].row_idx[last_row] = circuit_constructor.tau().at(real_variable_tags[cycle_idx]);
// Last node: sigma gets tagged and points to tau(tag) instead of wrapping to first node
mapping.sigmas[last_col].is_tag[last_row] = true;
mapping.sigmas[last_col].row_idx[last_row] = circuit_constructor.tau().at(real_variable_tags[cycle_idx]);

// All nodes except the last: sigma points to the next node in the cycle
for (size_t node_idx = 0; node_idx + 1 < cycle_size; ++node_idx) {
const cycle_node& current_node = cycle[node_idx];
const cycle_node& next_node = cycle[node_idx + 1];
// All nodes except the last: sigma points to the next node in the cycle
for (size_t node_idx = 0; node_idx + 1 < cycle_size; ++node_idx) {
const cycle_node& current_node = cycle[node_idx];
const cycle_node& next_node = cycle[node_idx + 1];

const auto current_row = static_cast<ptrdiff_t>(current_node.gate_idx);
const auto current_col = current_node.wire_idx;
// Point current node to next node.
mapping.sigmas[current_col].row_idx[current_row] = next_node.gate_idx;
mapping.sigmas[current_col].col_idx[current_row] = static_cast<uint8_t>(next_node.wire_idx);
const auto current_row = static_cast<ptrdiff_t>(current_node.gate_idx);
const auto current_col = current_node.wire_idx;
// Point current node to next node.
mapping.sigmas[current_col].row_idx[current_row] = next_node.gate_idx;
mapping.sigmas[current_col].col_idx[current_row] = static_cast<uint8_t>(next_node.wire_idx);
}
}
}
});

// Add information about public inputs so that the cycles can be altered later; See the construction of the
// permutation polynomials for details. This _only_ effects sigma_0, the 0th sigma polynomial, as the structure of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ std::vector<CyclicPermutation> TraceToPolynomials<Flavor>::populate_wires_and_se
RefVector<Selector<FF>> block_selectors = block.get_selectors();
// Insert the selector values for this block into the selector polynomials at the correct offset
// TODO(https://github.com/AztecProtocol/barretenberg/issues/398): implicit arithmetization/flavor consistency
for (size_t selector_idx = 0; selector_idx < block_selectors.size(); selector_idx++) {
auto& selector = block_selectors[selector_idx];
for (size_t row_idx = 0; row_idx < block_size; ++row_idx) {
size_t trace_row_idx = row_idx + offset;
selectors[selector_idx].set_if_valid_index(trace_row_idx, selector[row_idx]);
parallel_for([&](const ThreadChunk& chunk) {
for (size_t selector_idx = 0; selector_idx < block_selectors.size(); selector_idx++) {
auto& selector = block_selectors[selector_idx];
for (size_t row_idx : chunk.range(block_size)) {
size_t trace_row_idx = row_idx + offset;
selectors[selector_idx].set_if_valid_index(trace_row_idx, selector[row_idx]);
}
}
}
});
}

return copy_cycles;
Expand Down
Loading