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: Separate arithmetic gate in sort with edges #4866

Merged
merged 2 commits into from
Feb 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ TEST_F(join_split_tests, test_0_input_notes_and_detect_circuit_change)
// The below part detects any changes in the join-split circuit
constexpr uint32_t CIRCUIT_GATE_COUNT = 49492;
constexpr uint32_t GATES_NEXT_POWER_OF_TWO = 65535;
const uint256_t VK_HASH("c1032f787036ac943a5f064e599772d255423a221bba2af98ebce3baf2b53f56");
const uint256_t VK_HASH("893b71911c19c3a06a2658f0ef5f66f6e23455af7c8771a67c80addb060a479c");

auto number_of_gates_js = result.number_of_gates;
std::cout << get_verification_key()->sha256_hash() << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,8 @@ void UltraCircuitBuilder_<Arithmetization>::create_sort_constraint_with_edges(
ASSERT(variable_index.size() % gate_width == 0 && variable_index.size() > gate_width);
this->assert_valid_variables(variable_index);

// enforce range checks of first row and starting at start
blocks.main.populate_wires(variable_index[0], variable_index[1], variable_index[2], variable_index[3]);
// Add an arithmetic gate to ensure the first input is equal to the start value of the range being checked
blocks.main.populate_wires(variable_index[0], this->zero_idx, this->zero_idx, this->zero_idx);
++this->num_gates;
blocks.main.q_m().emplace_back(0);
blocks.main.q_1().emplace_back(1);
Expand All @@ -1022,16 +1022,17 @@ void UltraCircuitBuilder_<Arithmetization>::create_sort_constraint_with_edges(
blocks.main.q_c().emplace_back(-start);
blocks.main.q_arith().emplace_back(1);
blocks.main.q_4().emplace_back(0);
blocks.main.q_sort().emplace_back(1);
blocks.main.q_sort().emplace_back(0);
blocks.main.q_elliptic().emplace_back(0);
blocks.main.q_lookup_type().emplace_back(0);
blocks.main.q_aux().emplace_back(0);
if constexpr (HasAdditionalSelectors<Arithmetization>) {
blocks.main.pad_additional();
}
check_selector_length_consistency();
// enforce range check for middle rows
for (size_t i = gate_width; i < variable_index.size() - gate_width; i += gate_width) {

// enforce range check for all but the final row
for (size_t i = 0; i < variable_index.size() - gate_width; i += gate_width) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first sort gate can now be added in this loop (i=0 instead of i = gate_width) since it is no longer a special case


blocks.main.populate_wires(
variable_index[i], variable_index[i + 1], variable_index[i + 2], variable_index[i + 3]);
Expand Down
Loading