-
Notifications
You must be signed in to change notification settings - Fork 606
feat: Graph methods for circuit analysis (part 1) #7948
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f3ab6af
graph decription for ultra circuit builder
DanielKotov 10508e1
update_edges_for_sorted_variabes, cause it's useless now
DanielKotov 314f4f0
git ignore was added
DanielKotov 346f1bc
remove some commentaries from tests
DanielKotov 8375f46
remove all commentaries from another directiories and add my module i…
DanielKotov 86339b2
forget to return fr(2) in standard_circuit_builder.cpp in the last co…
DanielKotov ddf3e98
static analyzer based on graph description for UltraCircuitBuilder. a…
DanielKotov 0779bbb
tests for sha256 and blake2s
DanielKotov 8a52e6d
fixes
Rumata888 0956684
variables gate counts metric for AES and sha256
DanielKotov 637c203
remove changes from blake2s tests and circuit_builder_base
DanielKotov ff5df64
variables gate count for sha256 + tests
DanielKotov aef2249
remove some changes from workspace
DanielKotov bda8275
update for sha256 for PR
DanielKotov d9486f2
last commit
DanielKotov 20eb663
final version of UltraCircuit graph description for PR
DanielKotov ad369c8
add commentaries for every class methods, data sturctures and tests +…
DanielKotov 6e2933f
other changes for PR again
DanielKotov 445e02e
add comments + inline + this to all class member functions
DanielKotov d0f4fd4
corrected Sasha's comments + renamed tests + removed some info from
DanielKotov 2c842f6
Merge remote-tracking branch 'origin/master' into dk/boomerang_value
DanielKotov af9f73a
graph methods for circuit analysis
DanielKotov 0e238ff
remove my useless solution for standard circuit builder and tests for it
DanielKotov 14b6f32
cleanup
Rumata888 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
barretenberg/cpp/src/barretenberg/boomerang_value_detection/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| barretenberg_module(boomerang_value_detection stdlib_circuit_builders circuit_checker stdlib_primitives numeric stdlib_aes128 stdlib_sha256 stdlib_blake2s stdlib_blake3s) |
824 changes: 824 additions & 0 deletions
824
barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
119 changes: 119 additions & 0 deletions
119
barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| #pragma once | ||
| #include "barretenberg/stdlib_circuit_builders/standard_circuit_builder.hpp" | ||
| #include "barretenberg/stdlib_circuit_builders/ultra_circuit_builder.hpp" | ||
| #include <list> | ||
| #include <set> | ||
| #include <unordered_map> | ||
| #include <unordered_set> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| /* | ||
| * this class describes arithmetic circuit as an undirected graph, where vertices are variables from circuit. | ||
| * edges describe connections between variables through gates. We want to find variables that weren't properly | ||
| * constrainted/some connections were missed using additional metrics, like in how much gate variable was and number of | ||
| * connected components in the graph. if variable was in one connected component, it means that this variable wasn't | ||
| * constrained properly. if number of connected components > 1, it means that there were missed some connections between | ||
| * variables. | ||
| */ | ||
| template <typename FF> class Graph_ { | ||
|
Sarkoxed marked this conversation as resolved.
|
||
| public: | ||
| Graph_() = default; | ||
| Graph_(const Graph_& other) = delete; | ||
| Graph_(Graph_&& other) = delete; | ||
| Graph_& operator=(const Graph_& other) = delete; | ||
| Graph_&& operator=(Graph_&& other) = delete; | ||
| Graph_(const bb::StandardCircuitBuilder_<FF>& circuit_constructor); | ||
| Graph_(bb::UltraCircuitBuilder& ultra_circuit_constructor); | ||
|
|
||
| uint32_t to_real(bb::UltraCircuitBuilder& ultra_circuit_constructor, const uint32_t& variable_index) | ||
|
Sarkoxed marked this conversation as resolved.
|
||
| { | ||
| return ultra_circuit_constructor.real_variable_index[variable_index]; | ||
| }; | ||
| void process_gate_variables(bb::UltraCircuitBuilder& ultra_circuit_constructor, | ||
| std::vector<uint32_t>& gate_variables); | ||
|
|
||
| std::unordered_map<uint32_t, size_t> get_variables_gate_counts() { return this->variables_gate_counts; }; | ||
|
|
||
| std::vector<uint32_t> get_arithmetic_gate_connected_component(bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| size_t index); | ||
| std::vector<uint32_t> get_elliptic_gate_connected_component(bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| size_t index); | ||
| std::vector<uint32_t> get_plookup_gate_connected_component(bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| size_t index); | ||
| std::vector<uint32_t> get_sort_constraint_connected_component(bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| size_t index); | ||
|
|
||
| void add_new_edge(const uint32_t& first_variable_index, const uint32_t& second_variable_index); | ||
| std::vector<uint32_t> get_variable_adjacency_list(const uint32_t& variable_index) | ||
| { | ||
| return variable_adjacency_lists[variable_index]; | ||
| }; | ||
|
|
||
| void depth_first_search(const uint32_t& variable_index, | ||
| std::unordered_set<uint32_t>& is_used, | ||
| std::vector<uint32_t>& connected_component); | ||
| std::vector<std::vector<uint32_t>> find_connected_components(); | ||
|
|
||
| std::vector<uint32_t> find_variables_with_degree_one(); | ||
| std::unordered_set<uint32_t> get_variables_in_one_gate(); | ||
|
|
||
| bool find_arithmetic_gate_for_variable(bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| const uint32_t& variable_idx); | ||
| bool find_elliptic_gate_for_variable(bb::UltraCircuitBuilder& ultra_circuit_builder, const uint32_t& variable_idx); | ||
| bool find_lookup_gate_for_variable(bb::UltraCircuitBuilder& ultra_circuit_builder, const uint32_t& variable_idx); | ||
|
|
||
| size_t get_distance_between_variables(const uint32_t& first_variable_index, const uint32_t& second_variable_index); | ||
| bool check_vertex_in_connected_component(const std::vector<uint32_t>& connected_component, | ||
| const uint32_t& var_index); | ||
|
|
||
| void connect_all_variables_in_vector(bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| const std::vector<uint32_t>& variables_vector, | ||
| bool is_sorted_variables); | ||
| bool check_is_not_constant_variable(bb::UltraCircuitBuilder& ultra_circuit_builder, const uint32_t& variable_index); | ||
|
|
||
| std::pair<std::vector<uint32_t>, size_t> get_connected_component_with_index( | ||
| const std::vector<std::vector<uint32_t>>& connected_components, size_t index); | ||
|
|
||
| std::unordered_set<uint32_t> get_variables_in_one_gate_without_range_constraints( | ||
| bb::UltraCircuitBuilder& ultra_circuit_builder); | ||
|
|
||
| size_t process_current_decompose_chain(bb::UltraCircuitBuilder& ultra_circuit_constructor, | ||
| std::unordered_set<uint32_t>& variables_in_one_gate, | ||
| size_t index); | ||
| void process_current_plookup_gate(bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| std::unordered_set<uint32_t>& variables_in_one_gate, | ||
| size_t gate_index); | ||
| void remove_unnecessary_decompose_variables(bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| std::unordered_set<uint32_t>& variables_in_on_gate, | ||
| const std::unordered_set<uint32_t>& decompose_variables); | ||
| void remove_unnecessary_plookup_variables(bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| std::unordered_set<uint32_t>& variables_in_on_gate); | ||
| std::unordered_set<uint32_t> show_variables_in_one_gate(bb::UltraCircuitBuilder& ultra_circuit_builder); | ||
|
|
||
| void remove_unnecessary_aes_plookup_variables(std::unordered_set<uint32_t>& variables_in_one_gate, | ||
| bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| bb::plookup::BasicTableId& table_id, | ||
| size_t gate_index); | ||
| void remove_unnecessary_sha256_plookup_variables(std::unordered_set<uint32_t>& variables_in_one_gate, | ||
| bb::UltraCircuitBuilder& ultra_circuit_builder, | ||
| bb::plookup::BasicTableId& table_id, | ||
| size_t gate_index); | ||
|
|
||
| void print_graph(); | ||
| void print_connected_components(); | ||
| void print_variables_gate_counts(); | ||
| void print_variables_edge_counts(); | ||
| ~Graph_() = default; | ||
|
|
||
| private: | ||
| std::unordered_map<uint32_t, std::vector<uint32_t>> | ||
| variable_adjacency_lists; // we use this data structure to contain information about variables and their | ||
| // connections between each other | ||
| std::unordered_map<uint32_t, size_t> | ||
| variables_gate_counts; // we use this data structure to count, how many gates use every variable | ||
| std::unordered_map<uint32_t, size_t> | ||
| variables_degree; // we use this data structure to count, how many every variable have edges | ||
| }; | ||
|
|
||
| using Graph = Graph_<bb::fr>; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.