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);
88 std::vector<uint32_t>
to_real(std::vector<uint32_t>& variable_indices)
90 std::vector<uint32_t> real_variable_indices;
91 real_variable_indices.reserve(variable_indices.size());
92 for (
auto& variable_index : variable_indices) {
93 real_variable_indices.push_back(
to_real(variable_index));
95 return real_variable_indices;
97 uint32_t
to_real(
const uint32_t& variable_index)
const
121 void add_new_edge(
const uint32_t& first_variable_index,
const uint32_t& second_variable_index);
123 std::unordered_set<uint32_t>& is_used,
124 std::vector<uint32_t>& connected_component);
132 const uint32_t& var_index);
170 std::unordered_map<uint32_t, size_t>
172 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
bool is_gate_sorted_rom(size_t memory_block_idx, size_t gate_idx) const
this method checks if current gate is sorted ROM gate
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::unordered_set< uint32_t > constant_variable_indices_set
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
void remove_unnecessary_decompose_variables(const std::unordered_set< uint32_t > &decompose_variables)
this method removes unnecessary variables from decompose chains
std::vector< ConnectedComponent > find_connected_components()
this methond finds all connected components in the graph described by adjacency lists and marks some ...
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
std::pair< std::vector< ConnectedComponent >, std::unordered_set< uint32_t > > analyze_circuit(bool filter_cc=true)
this functions was made for more convenient testing process
void print_elliptic_gate_info(size_t gate_idx, auto &block)
this method prints all information about elliptic gate where variable was found
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
void save_constant_variable_indices()
this method needs to save all constant variables indices in one data structure in order to not go thr...
std::optional< size_t > find_block_index(const auto &block)
this method finds index of the block in circuit builder by comparing pointers to blocks
bool variable_only_in_sorted_rom_gates(uint32_t var_idx, size_t blk_idx) const
this method checks that every gate for given variable in a given block is sorted ROM gate
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::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 ...
void print_variables_gate_counts()
this method prints a number of gates for each variable
void mark_process_rom_connected_component()
this method marks some connected components if they were created by function process_rom_array....
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
RamTranscript contains the RamRecords for a particular RAM table (recording READ and WRITE operations...
RomTranscript contains the RomRecords for a particular ROM table as well as the vector whose ith entr...
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