Skip to content

Commit

Permalink
Reserve lookup tables for components
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn authored and nkaskov committed Dec 1, 2023
1 parent 3bb2f6e commit a5fc5a8
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/nil/blueprint/boolean/logic_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ namespace nil {
using arithmetization_type = crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>;
components::logic_and<arithmetization_type> component_instance(witnesses);

if constexpr( use_lookups<components::logic_and<arithmetization_type>>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

typename components::logic_and<arithmetization_type>::input_type instance_input;
instance_input.input[0] = x;
instance_input.input[1] = y;
Expand Down
14 changes: 14 additions & 0 deletions include/nil/blueprint/curves/addition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

struct var_ec_point {
var X;
var Y;
Expand Down Expand Up @@ -107,6 +114,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

using non_native_policy_type = basic_non_native_policy<BlueprintFieldType>;

struct var_ec_point {
Expand Down
14 changes: 14 additions & 0 deletions include/nil/blueprint/curves/multiplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

struct var_ec_point {
var X;
var Y;
Expand Down Expand Up @@ -109,6 +116,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0, 253));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs(), 253, nil::blueprint::components::bit_shift_mode::RIGHT);

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

using non_native_policy_type = basic_non_native_policy<BlueprintFieldType>;

struct var_ec_point {
Expand Down
14 changes: 14 additions & 0 deletions include/nil/blueprint/fields/addition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

var x = variables[operand0];
var y = variables[operand1];

Expand Down Expand Up @@ -99,6 +106,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

std::vector<var> operand0_vars = vectors[operand0];
std::vector<var> operand1_vars = vectors[operand1];

Expand Down
7 changes: 7 additions & 0 deletions include/nil/blueprint/fields/division.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

var x = variables[operand0];
var y = variables[operand1];

Expand Down
14 changes: 14 additions & 0 deletions include/nil/blueprint/fields/multiplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

var x = variables[operand0];
var y = variables[operand1];

Expand Down Expand Up @@ -99,6 +106,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

std::vector<var> operand0_vars = vectors[operand0];
std::vector<var> operand1_vars = vectors[operand1];

Expand Down
14 changes: 14 additions & 0 deletions include/nil/blueprint/fields/subtraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

var x = variables[operand0];
var y = variables[operand1];

Expand Down Expand Up @@ -99,6 +106,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

std::vector<var> operand0_vars = vectors[operand0];
std::vector<var> operand1_vars = vectors[operand1];

Expand Down
7 changes: 7 additions & 0 deletions include/nil/blueprint/hashes/sha2_256.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ namespace nil {
component_type component_instance(p.witness, detail::ManifestReader<component_type, ArithmetizationParams>::get_constants(),
detail::ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

components::generate_circuit(component_instance, bp, assignmnt, instance_input, start_row);

typename component_type::result_type component_result =
Expand Down
14 changes: 14 additions & 0 deletions include/nil/blueprint/hashes/sha2_512.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ namespace nil {
detail::ManifestReader<sha2_512_component_type, ArithmetizationParams>::get_constants(),
detail::ManifestReader<sha2_512_component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<sha2_512_component_type>() ){
auto lookup_tables = sha2_512_component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

components::generate_circuit(sha2_512_component_instance, bp, assignmnt, sha2_512_instance_input, start_row);

typename sha2_512_component_type::result_type sha2_512_component_result =
Expand All @@ -98,6 +105,13 @@ namespace nil {
detail::ManifestReader<reduction_component_type, ArithmetizationParams>::get_constants(),
detail::ManifestReader<reduction_component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<reduction_component_type>() ){
auto lookup_tables = reduction_component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

start_row = assignmnt.allocated_rows();

typename reduction_component_type::input_type reduction_instance_input = {sha2_512_component_result.output_state};
Expand Down
6 changes: 6 additions & 0 deletions include/nil/blueprint/integers/bit_shift.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ namespace nil {

component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs(), Bitness, Shift, left_or_right);

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

components::generate_circuit(component_instance, bp, assignment, {x}, start_row);
return components::generate_assignments(component_instance, assignment, {x}, start_row);
Expand Down
7 changes: 7 additions & 0 deletions include/nil/blueprint/integers/division_remainder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ namespace nil {
const auto p = PolicyManager::get_parameters(ManifestReader<component_type, ArithmetizationParams>::get_witness(0, Bitness, true));
component_type component_instance(p.witness, ManifestReader<component_type, ArithmetizationParams>::get_constants(), ManifestReader<component_type, ArithmetizationParams>::get_public_inputs(), Bitness, true);

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
bp.reserve_table(k);
}
};

var x = variables[operand0];
var y = variables[operand1];

Expand Down
13 changes: 12 additions & 1 deletion include/nil/blueprint/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ namespace nil {
component_type component_instance(p.witness, detail::ManifestReader<component_type, ArithmetizationParams>::get_constants(),
detail::ManifestReader<component_type, ArithmetizationParams>::get_public_inputs());

if constexpr( use_lookups<component_type>() ){
auto lookup_tables = component_instance.component_lookup_tables();
for(auto &[k,v]:lookup_tables){
circuits[currProverIdx].reserve_table(k);
}
};

components::generate_circuit(component_instance, circuits[currProverIdx], assignments[currProverIdx], instance_input, start_row);

typename component_type::result_type component_result =
Expand All @@ -411,7 +418,11 @@ namespace nil {
return true;
}
case llvm::Intrinsic::assigner_sha2_256: {
handle_sha2_256_component<BlueprintFieldType, ArithmetizationParams>(inst, frame, circuits[currProverIdx], assignments[currProverIdx], start_row, next_prover);
handle_sha2_256_component<BlueprintFieldType, ArithmetizationParams>(inst, frame,
circuits[currProverIdx],
assignments[currProverIdx],
start_row,
next_prover);
return true;
}
case llvm::Intrinsic::assigner_sha2_512: {
Expand Down

0 comments on commit a5fc5a8

Please sign in to comment.