7#include <unordered_map>
8#include <unordered_set>
32 size_t combined_hash = 0;
34 constexpr size_t HASH_COMBINE_CONSTANT = 0x9e3779b9;
35 auto hash_combiner = [](
size_t lhs,
size_t rhs) {
36 return lhs ^ (rhs + HASH_COMBINE_CONSTANT + (lhs << 6) + (lhs >> 2));
47 return (p1.first == p2.first && p1.second == p2.second);
86 std::vector<uint32_t>
to_real(std::vector<uint32_t>& variable_indices)
88 std::vector<uint32_t> real_variable_indices;
89 real_variable_indices.reserve(variable_indices.size());
90 for (
auto& variable_index : variable_indices) {
91 real_variable_indices.push_back(
to_real(variable_index));
93 return real_variable_indices;
95 uint32_t
to_real(
const uint32_t& variable_index)
const
119 void add_new_edge(
const uint32_t& first_variable_index,
const uint32_t& second_variable_index);
121 std::unordered_set<uint32_t>& is_used,
122 std::vector<uint32_t>& connected_component);
127 const uint32_t& var_index);
167 std::unordered_map<uint32_t, size_t>
169 std::unordered_map<uint32_t, size_t>
void print_delta_range_gate_info(size_t gate_idx, auto &block)
this method prints all information about range constrain gate where variable was found
void process_execution_trace()
void print_memory_gate_info(size_t gate_idx, auto &block)
this method prints all information about memory gate where variable was found
void print_plookup_gate_info(size_t gate_idx, auto &block)
this method prints all information about plookup gate where variable was found
std::vector< uint32_t > get_ram_table_connected_component(const bb::RamTranscript &ram_array)
this method gets the RAM table connected component by processing RAM transcript records
std::unordered_map< uint32_t, std::vector< uint32_t > > variable_adjacency_lists
std::vector< uint32_t > get_eccop_part_connected_component(size_t index, size_t block_idx, auto &blk)
this method creates connected components from elliptic curve operation gates
std::vector< uint32_t > to_real(std::vector< uint32_t > &variable_indices)
Convert a vector of variable indices to their real indices.
std::unordered_map< KeyPair, std::vector< size_t >, KeyHasher, KeyEquals > variable_gates
std::vector< uint32_t > get_memory_gate_connected_component(size_t index, size_t block_idx, auto &blk)
this method creates connected components from Memory gates (RAM and ROM consistency checks)
StaticAnalyzer_ & operator=(const StaticAnalyzer_ &other)=delete
std::vector< uint32_t > get_plookup_gate_connected_component(size_t index, size_t block_idx, auto &blk)
this method creates connected components from plookup gates
std::pair< std::vector< ConnectedComponent >, std::unordered_set< uint32_t > > analyze_circuit()
void remove_unnecessary_decompose_variables(const std::unordered_set< uint32_t > &decompose_variables)
this method removes unnecessary variables from decompose chains
void depth_first_search(const uint32_t &variable_index, std::unordered_set< uint32_t > &is_used, std::vector< uint32_t > &connected_component)
this method implements depth-first search algorithm for undirected graphs
bool check_is_not_constant_variable(const uint32_t &variable_index)
this method checks whether the variable with given index is not constant
std::vector< uint32_t > get_arithmetic_gate_connected_component(size_t index, size_t block_idx, auto &blk)
this method creates connected components from arithmetic gates
void remove_unnecessary_sha256_plookup_variables(bb::plookup::BasicTableId &table_id, size_t gate_index)
this method removes false cases in sha256 lookup tables. tables which are enumerated in the unordered...
std::vector< uint32_t > get_eccop_connected_component(size_t index, size_t block_idx, auto &blk)
std::unordered_set< uint32_t > get_variables_in_one_gate()
this method returns a final set of variables that were in one gate
std::vector< uint32_t > get_non_native_field_gate_connected_component(size_t index, size_t block_idx, auto &blk)
this method creates connected components from Non-Native Field gates (bigfield operations)
void remove_record_witness_variables()
this method removes record witness variables from variables in one gate. initially record witness is ...
void print_variable_info(const uint32_t real_idx)
this method prints all information about gates where variable was found
void remove_unnecessary_range_constrains_variables()
this method removes variables from range constraints that are not security critical
void print_elliptic_gate_info(size_t gate_idx, auto &block)
this method prints all information about elliptic gate where variable was found
size_t find_block_index(const auto &block)
this method finds index of the block in circuit builder by comparing pointers to blocks
StaticAnalyzer_()=default
std::vector< uint32_t > get_databus_connected_component(size_t index, size_t block_idx, auto &blk)
this method creates connected components from databus gates
std::unordered_set< uint32_t > fixed_variables
void connect_all_variables_in_vector(const std::vector< uint32_t > &variables_vector)
this method connects 2 variables if they are in one gate and 1) have different indices,...
void print_connected_components_info()
this method prints additional information about connected components that were found in the graph
std::vector< uint32_t > get_rom_table_connected_component(const bb::RomTranscript &rom_array)
this method gets the ROM table connected component by processing ROM transcript records
~StaticAnalyzer_()=default
std::vector< uint32_t > get_poseido2s_gate_connected_component(size_t index, size_t block_idx, auto &blk)
this method creates connected components from poseidon2 gates
void print_poseidon2s_gate_info(size_t gate_idx, auto &block)
this method prints all information about poseidon2s gate where variable was found
std::unordered_map< uint32_t, size_t > variables_gate_counts
std::unordered_map< uint32_t, size_t > get_variables_gate_counts() const
uint32_t to_real(const uint32_t &variable_index) const
std::vector< uint32_t > get_sort_constraint_connected_component(size_t index, size_t block_idx, auto &blk)
this method creates connected components from sorted constraints
std::vector< ConnectedComponent > connected_components
std::vector< ConnectedComponent > main_connected_components
void remove_unnecessary_aes_plookup_variables(bb::plookup::BasicTableId &table_id, size_t gate_index)
this method removes false positive cases variables from aes plookup tables. AES_SBOX_MAP,...
void process_gate_variables(std::vector< uint32_t > &gate_variables, size_t gate_index, size_t blk_idx)
this method processes variables from a gate by removing duplicates and updating tracking structures
CircuitBuilder & circuit_builder
void remove_unnecessary_plookup_variables()
this method removes false cases plookup variables from variables in one gate
StaticAnalyzer_(StaticAnalyzer_ &&other)=delete
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::vector< uint32_t > get_elliptic_gate_connected_component(size_t index, size_t block_idx, auto &blk)
this method creates connected components from elliptic gates
void print_nnf_gate_info(size_t gate_idx, auto &block)
this method prints all information about non natife field gate where variable was found
bool check_vertex_in_connected_component(const std::vector< uint32_t > &connected_component, const uint32_t &var_index)
void print_arithmetic_gate_info(size_t gate_idx, auto &block)
this method prints all information about arithmetic gate where variable was found
void process_current_plookup_gate(size_t gate_index)
this method removes false cases in lookup table for a given gate. it uses all functions above for loo...
StaticAnalyzer_(const StaticAnalyzer_ &other)=delete
void mark_range_list_connected_components()
this method marks some connected componets like they represent range lists tool needs this method to ...
std::vector< ConnectedComponent > find_connected_components(bool return_all_connected_components=false)
this methond finds all connected components in the graph described by adjacency lists
void print_variables_gate_counts()
this method prints a number of gates for each variable
std::unordered_set< uint32_t > variables_in_one_gate
std::unordered_map< uint32_t, size_t > variables_degree
StaticAnalyzer_ && operator=(StaticAnalyzer_ &&other)=delete
size_t process_current_decompose_chain(size_t index)
this method removes variables that were created in a function decompose_into_default_range because th...
void add_new_edge(const uint32_t &first_variable_index, const uint32_t &second_variable_index)
this method creates an edge between two variables in graph. All needed checks in a function above
void mark_finalize_connected_components()
this method marks some connected components like they represent separated finalize blocks the point i...
std::pair< uint32_t, size_t > KeyPair
StaticAnalyzer_< bb::fr, bb::UltraCircuitBuilder > UltraStaticAnalyzer
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Each ram array is an instance of memory transcript. It saves values and indexes for a particular memo...
Each rom array is an instance of memory transcript. It saves values and indexes for a particular memo...
std::vector< uint32_t > variable_indices
ConnectedComponent(const std::vector< uint32_t > &vector)
const std::vector< uint32_t > & vars() const
ConnectedComponent()=default
bool operator()(const KeyPair &p1, const KeyPair &p2) const
size_t operator()(const KeyPair &pair) const
TranslatorFlavor::CircuitBuilder CircuitBuilder