Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit

Permalink
246 sha tables (#248)
Browse files Browse the repository at this point in the history
* Proofs generation and verification updated #222

First working test #222

Add test with component-specific table#222

Update github actions #222

Lookup table definition changed not to generate lookup table if it's not necessary#222

Register table function changed #222

Changed lookup_table_definition * to shared_ptr #222

Add blueprint_algebra_fields_plonk_non_native_lookup_logic_ops_test to CI #222

Reserved table indices counting algorithm changed #222

Minor changes from ZK#222

CI crypto3 ref changed #222

Test plonk component proof generation switched off #222

Uncomment lookup constraints in sha-256 component #237

Change table packer in test_plonk_component.hpp

Change table packer call in test_plonk_component.hpp #237

Update suite ref in CI #237

Two more lookup gates uncommented #237

Error in lookup table generation corrected #237

Some parameters changed to increase efficiency #237

Added weak connectedness check variant. (#235)

222 blueprint lookup tables (#231)

* Proofs generation and verification updated #222

* First working test #222

* Add test with component-specific table#222

* Update github actions #222

* Lookup table definition changed not to generate lookup table if it's not necessary#222

* Register table function changed #222

* Changed lookup_table_definition * to shared_ptr #222

* Add blueprint_algebra_fields_plonk_non_native_lookup_logic_ops_test to CI #222

* Reserved table indices counting algorithm changed #222

* Minor changes from ZK#222

* CI crypto3 ref changed #222

* Test plonk component proof generation switched off #222

* Added lookup satisfiability check.

* Print full log for unsatisfied lookup constraints #237

Fixed subtables processing in satisfiability_check #237

* add range checks

* Sha table generators and constraint refactor.

* Sha256 naming/constraint fixes.

---------

Co-authored-by: e.tatuzova <[email protected]>
Co-authored-by: shatooon <[email protected]>
  • Loading branch information
3 people authored Nov 6, 2023
1 parent 0cbb80d commit 1e40ce2
Show file tree
Hide file tree
Showing 19 changed files with 111,145 additions and 472 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
uses: actions/checkout@v3
with:
repository: ${{ env.SUITE_REPO }}
ref: 81-lookup-tables-packer
submodules: recursive
fetch-depth: 0

Expand Down
13 changes: 10 additions & 3 deletions include/nil/blueprint/blueprint/plonk/circuit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,18 @@ namespace nil {
_lookup_library.reserve_table(name);
}

virtual const std::map<std::string, std::size_t> &get_reserved_indices(){
return _lookup_library.get_reserved_indices();
virtual const typename lookup_library<BlueprintFieldType>::left_reserved_type
&get_reserved_indices() const {
return _lookup_library.get_reserved_indices().left;
}

virtual const std::map<std::string, std::shared_ptr<lookup_table_definition>> &get_reserved_tables(){
// used in satisfiability check
virtual const typename lookup_library<BlueprintFieldType>::right_reserved_type
&get_reserved_indices_right() const {
return _lookup_library.get_reserved_indices().right;
}

virtual const std::map<std::string, std::shared_ptr<lookup_table_definition>> &get_reserved_tables() {
return _lookup_library.get_reserved_tables();
}

Expand Down
8 changes: 7 additions & 1 deletion include/nil/blueprint/blueprint/plonk/circuit_proxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,16 @@ namespace nil {
circuit_ptr->reserve_table(name);
}

const std::map<std::string, std::size_t> &get_reserved_indices() override {
const typename lookup_library<BlueprintFieldType>::left_reserved_type
&get_reserved_indices() const override {
return circuit_ptr->get_reserved_indices();
}

const typename lookup_library<BlueprintFieldType>::right_reserved_type &
get_reserved_indices_right() const override {
return circuit_ptr->get_reserved_indices_right();
}

const std::map<std::string, std::shared_ptr<lookup_table_definition>> &get_reserved_tables() override {
return circuit_ptr->get_reserved_tables();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ namespace nil {
constexpr static const std::size_t gates_amount = 1;

virtual crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType> op_lookup_constraint(
const std::array<var, 2 + 1> &witnesses,
const std::map<std::string, std::size_t> lookup_tables_indices
const std::array<var, 2 + 1> &witnesses,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&bp
) const = 0;

virtual value_type result_assignment(const std::array<value_type, 2> &input_values) const = 0;
Expand Down Expand Up @@ -175,8 +176,7 @@ namespace nil {
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
const typename plonk_boolean_lookup_op_component<BlueprintFieldType, ArithmetizationParams>::input_type
&instance_input,
const std::map<std::string, std::size_t> lookup_tables_indices
&instance_input
) {

using var = typename plonk_boolean_lookup_op_component<BlueprintFieldType, ArithmetizationParams>::var;
Expand All @@ -185,8 +185,8 @@ namespace nil {
for (std::size_t col_idx = 0; col_idx < witnesses.size(); col_idx++) {
witnesses[col_idx] = var(component.W(col_idx), 0);
}
auto constraint = component.op_lookup_constraint(witnesses, lookup_tables_indices);
auto selector_id = bp.add_lookup_gate({constraint});
auto constraint = component.op_lookup_constraint(witnesses, bp);
auto selector_id = bp.add_lookup_gate({constraint});
return selector_id;
}

Expand Down Expand Up @@ -223,10 +223,9 @@ namespace nil {
&instance_input,
const std::size_t start_row_index
) {
const std::map<std::string, std::size_t> &lookup_tables_indices = bp.get_reserved_indices();
using component_type = plonk_boolean_lookup_op_component<BlueprintFieldType, ArithmetizationParams>;

std::size_t selector_index = generate_gates(component, bp, assignment, instance_input, lookup_tables_indices);
std::size_t selector_index = generate_gates(component, bp, assignment, instance_input);

assignment.enable_selector(selector_index, start_row_index);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace nil {

template<typename BlueprintFieldType, typename ArithmetizationParams>
class lookup_logic_and<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
: public boolean_lookup_op_component<crypto3::zk::snark::plonk_constraint_system< BlueprintFieldType, ArithmetizationParams>>
: public boolean_lookup_op_component<crypto3::zk::snark::plonk_constraint_system< BlueprintFieldType, ArithmetizationParams>>
{
using lookup_table_definition = typename nil::crypto3::zk::snark::detail::lookup_table_definition<BlueprintFieldType>;

Expand Down Expand Up @@ -104,11 +104,13 @@ namespace nil {
}

virtual crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType> op_lookup_constraint(
const std::array<var, 2 + 1> &witnesses,
const std::map<std::string, std::size_t> lookup_tables_indices
const std::array<var, 2 + 1> &witnesses,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&bp
) const {
crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType> result;
result.table_id = lookup_tables_indices.at("binary_and_table/full");
bp.reserve_table("binary_and_table/full");
result.table_id = bp.get_reserved_indices().at("binary_and_table/full");
result.lookup_input = {witnesses[0], witnesses[1], witnesses[2]};
return result;
}
Expand All @@ -117,13 +119,6 @@ namespace nil {
return input_values[0] * input_values[1];
}

std::vector<std::shared_ptr<lookup_table_definition>> component_custom_lookup_tables(){
std::vector<std::shared_ptr<lookup_table_definition>> result = {};
binary_and_table = std::shared_ptr<lookup_table_definition>(new binary_and_table_type());
result.push_back(binary_and_table);
return result;
}

std::map<std::string, std::size_t> component_lookup_tables(){
std::map<std::string, std::size_t> lookup_tables;
lookup_tables["binary_and_table/full"] = 0; // REQUIRED_TABLE
Expand Down Expand Up @@ -260,11 +255,13 @@ namespace nil {
}

virtual crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType> op_lookup_constraint(
const std::array<var, 2 + 1> &witnesses,
const std::map<std::string, std::size_t> lookup_tables_indices
const std::array<var, 2 + 1> &witnesses,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&bp
) const {
crypto3::zk::snark::plonk_lookup_constraint<BlueprintFieldType> result;
result.table_id = lookup_tables_indices.at("binary_xor_table/full");
bp.reserve_table("binary_xor_table/full");
result.table_id = bp.get_reserved_indices().at("binary_xor_table/full");
result.lookup_input = {witnesses[0], witnesses[1], witnesses[2]};
return result;
}
Expand Down
Loading

0 comments on commit 1e40ce2

Please sign in to comment.