Skip to content

Commit d0bfb78

Browse files
akokoshnakokoshn
authored andcommitted
Use types from crypto3 for marshaling circuit and assignment table
1 parent f67ed16 commit d0bfb78

File tree

1 file changed

+18
-49
lines changed

1 file changed

+18
-49
lines changed

bin/assigner/src/main.cpp

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,8 @@ void print_circuit(const circuit_proxy<ArithmetizationType> &circuit_proxy,
7171
const assignment_proxy<ArithmetizationType> &table_proxy,
7272
bool rename_required, std::ostream &out = std::cout) {
7373
using TTypeBase = nil::marshalling::field_type<Endianness>;
74-
using plonk_constraint_system = nil::marshalling::types::bundle<
75-
TTypeBase, std::tuple<
76-
nil::crypto3::marshalling::types::plonk_gates<TTypeBase, typename ConstraintSystemType::gates_container_type::value_type >, // gates
77-
nil::crypto3::marshalling::types::plonk_copy_constraints<TTypeBase, typename ConstraintSystemType::field_type>, // copy constraints
78-
nil::crypto3::marshalling::types::plonk_lookup_gates<TTypeBase, typename ConstraintSystemType::lookup_gates_container_type::value_type>, // lookup constraints
79-
// If we don't have lookup gates, we don't need lookup tables
80-
nil::crypto3::marshalling::types::plonk_lookup_tables< TTypeBase, typename ConstraintSystemType::lookup_tables_type::value_type > // lookup tables
81-
>
82-
>;
74+
using value_marshalling_type =
75+
nil::crypto3::marshalling::types::plonk_constraint_system<TTypeBase, ConstraintSystemType>;
8376
using AssignmentTableType = assignment_proxy<ArithmetizationType>;
8477
using variable_type = crypto3::zk::snark::plonk_variable<typename AssignmentTableType::field_type::value_type>;
8578

@@ -136,7 +129,7 @@ void print_circuit(const circuit_proxy<ArithmetizationType> &circuit_proxy,
136129
}
137130

138131
auto filled_val =
139-
plonk_constraint_system(std::make_tuple(
132+
value_marshalling_type(std::make_tuple(
140133
nil::crypto3::marshalling::types::fill_plonk_gates<Endianness, typename ConstraintSystemType::gates_container_type::value_type>(used_gates),
141134
nil::crypto3::marshalling::types::fill_plonk_copy_constraints<Endianness, typename ConstraintSystemType::variable_type>(used_copy_constraints),
142135
nil::crypto3::marshalling::types::fill_plonk_lookup_gates<Endianness, typename ConstraintSystemType::lookup_gates_container_type::value_type>(used_lookup_gates),
@@ -232,43 +225,9 @@ void print_assignment_table(const assignment_proxy<ArithmetizationType> &table_p
232225
total_size = padded_rows_amount * total_columns;
233226

234227
using TTypeBase = nil::marshalling::field_type<Endianness>;
235-
using plonk_assignment_table = nil::marshalling::types::bundle<
236-
TTypeBase,
237-
std::tuple<
238-
nil::marshalling::types::integral<TTypeBase, std::size_t>, // witness_amount
239-
nil::marshalling::types::integral<TTypeBase, std::size_t>, // public_input_amount
240-
nil::marshalling::types::integral<TTypeBase, std::size_t>, // constant_amount
241-
nil::marshalling::types::integral<TTypeBase, std::size_t>, // selector_amount
242-
243-
nil::marshalling::types::integral<TTypeBase, std::size_t>, // usable_rows
244-
nil::marshalling::types::integral<TTypeBase, std::size_t>, // padded_rows_amount
245-
246-
// table_witness_values
247-
nil::marshalling::types::array_list<
248-
TTypeBase,
249-
nil::crypto3::marshalling::types::field_element<TTypeBase, typename AssignmentTableType::field_type::value_type>,
250-
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<TTypeBase, std::size_t>>
251-
>,
252-
// table_public_input_values
253-
nil::marshalling::types::array_list<
254-
TTypeBase,
255-
nil::crypto3::marshalling::types::field_element<TTypeBase, typename AssignmentTableType::field_type::value_type>,
256-
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<TTypeBase, std::size_t>>
257-
>,
258-
// table_constant_values
259-
nil::marshalling::types::array_list<
260-
TTypeBase,
261-
nil::crypto3::marshalling::types::field_element<TTypeBase, typename AssignmentTableType::field_type::value_type>,
262-
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<TTypeBase, std::size_t>>
263-
>,
264-
// table_selector_values
265-
nil::marshalling::types::array_list<
266-
TTypeBase,
267-
nil::crypto3::marshalling::types::field_element<TTypeBase, typename AssignmentTableType::field_type::value_type>,
268-
nil::marshalling::option::sequence_size_field_prefix<nil::marshalling::types::integral<TTypeBase, std::size_t>>
269-
>
270-
>
271-
>;
228+
using table_value_marshalling_type =
229+
nil::crypto3::marshalling::types::plonk_assignment_table<TTypeBase, AssignmentTableType>;
230+
272231
using column_type = typename crypto3::zk::snark::plonk_column<BlueprintFieldType>;
273232

274233
std::vector<typename AssignmentTableType::field_type::value_type> table_witness_values( padded_rows_amount * witness_size , 0);
@@ -380,7 +339,7 @@ void print_assignment_table(const assignment_proxy<ArithmetizationType> &table_p
380339
ASSERT_MSG(witness_idx + pub_inp_idx + constant_idx + selector_idx == total_size, "Printed index not equal required assignment size" );
381340
}
382341

383-
auto filled_val = plonk_assignment_table(std::make_tuple(
342+
auto filled_val = table_value_marshalling_type(std::make_tuple(
384343
nil::marshalling::types::integral<TTypeBase, std::size_t>(witness_size),
385344
nil::marshalling::types::integral<TTypeBase, std::size_t>(public_input_size + shared_size),
386345
nil::marshalling::types::integral<TTypeBase, std::size_t>(constant_size),
@@ -547,14 +506,24 @@ int curve_dependent_main(std::string bytecode_file_name,
547506
lookup_columns_indices.resize(LookupConstantColumns);
548507
// fill ComponentConstantColumns, ComponentConstantColumns + 1, ...
549508
std::iota(lookup_columns_indices.begin(), lookup_columns_indices.end(), ComponentConstantColumns);
509+
// check if lookup selectors were not used
510+
auto max_used_selector_idx = assigner_instance.assignments[0].selectors_amount() - 1;
511+
while (max_used_selector_idx > 0) {
512+
max_used_selector_idx--;
513+
if (assigner_instance.assignments[0].selector(max_used_selector_idx).size() > 0) {
514+
break;
515+
}
516+
}
517+
518+
ASSERT(max_used_selector_idx < ComponentSelectorColumns);
550519

551520
auto usable_rows_amount = zk::snark::pack_lookup_tables_horizontal(
552521
assigner_instance.circuits[0].get_reserved_indices(),
553522
assigner_instance.circuits[0].get_reserved_tables(),
554523
assigner_instance.circuits[0].get(),
555524
assigner_instance.assignments[0].get(),
556525
lookup_columns_indices,
557-
ComponentSelectorColumns,
526+
max_used_selector_idx + 1,
558527
0,
559528
max_lookup_rows
560529
);

0 commit comments

Comments
 (0)