Skip to content

Commit

Permalink
339 clean pi continue (#146)
Browse files Browse the repository at this point in the history
put pointers into constant column instead of PI
  • Loading branch information
CblPOK-git authored Nov 14, 2023
1 parent bce3760 commit 9cd288e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
3 changes: 1 addition & 2 deletions include/nil/blueprint/boolean/logic_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row,
std::size_t &public_input_idx) {
std::uint32_t start_row) {

std::array<std::uint32_t, 2 + 1> witnesses;
for (std::uint32_t i = 0; i < 2 + 1; i++) {
Expand Down
3 changes: 1 addition & 2 deletions include/nil/blueprint/comparison/comparison.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ namespace nil {
circuit_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment_proxy<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
&assignment,
std::uint32_t start_row,
std::size_t &public_input_idx) {
std::uint32_t start_row) {

using eq_component_type = components::equality_flag<
crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>, BlueprintFieldType>;
Expand Down
19 changes: 13 additions & 6 deletions include/nil/blueprint/input_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace nil {
public:
InputReader(stack_frame<var> &frame, program_memory<var> &memory, Assignment &assignmnt, LayoutResolver &layout_resolver) :
frame(frame), layout_resolver(layout_resolver), memory(memory),
assignmnt(assignmnt), public_input_idx(0), private_input_idx(0) {}
assignmnt(assignmnt), public_input_idx(0), private_input_idx(0), constant_idx(0) {}

template<typename InputType>
var put_into_assignment(InputType &input, bool is_private) {
Expand All @@ -58,6 +58,12 @@ namespace nil {
}
}

template<typename InputType>
var pointer_into_assignment(InputType &ptr) {
assignmnt.constant(1, constant_idx) = ptr; // TODO: column index is hardcoded but shouldn't be in the future
return var(1, constant_idx++, false, var::column_type::constant);
}

std::vector<var> process_curve (llvm::EllipticCurveType *curve_type, const boost::json::object &value, bool is_private) {
size_t arg_len = curve_arg_num<BlueprintFieldType>(curve_type);
ASSERT_MSG(arg_len >= 2, "arg_len of curveTy cannot be less than two");
Expand Down Expand Up @@ -272,7 +278,7 @@ namespace nil {
}
const auto &json_str = value.at("string").as_string();
ptr_type ptr = memory.add_cells(std::vector<unsigned>(json_str.size() + 1, 1));
auto pointer_var = put_into_assignment(ptr, is_private);
auto pointer_var = pointer_into_assignment(ptr);
frame.scalars[arg] = pointer_var;

for (char c : json_str) {
Expand All @@ -290,15 +296,15 @@ namespace nil {
bool try_struct(llvm::Value *arg, llvm::StructType *struct_type, const boost::json::object &value, bool is_private) {
ptr_type ptr = memory.add_cells(layout_resolver.get_type_layout<BlueprintFieldType>(struct_type));
process_struct(struct_type, value, ptr, is_private);
auto variable = put_into_assignment(ptr, is_private);
auto variable = pointer_into_assignment(ptr);
frame.scalars[arg] = variable;
return true;
}

bool try_array(llvm::Value *arg, llvm::ArrayType *array_type, const boost::json::object &value, bool is_private) {
ptr_type ptr = memory.add_cells(layout_resolver.get_type_layout<BlueprintFieldType>(array_type));
process_array(array_type, value, ptr, is_private);
auto variable = put_into_assignment(ptr, is_private);;
auto variable = pointer_into_assignment(ptr);
frame.scalars[arg] = variable;
return true;
}
Expand Down Expand Up @@ -402,7 +408,7 @@ namespace nil {
if (current_arg->hasStructRetAttr()) {
auto pointee = current_arg->getAttribute(llvm::Attribute::StructRet).getValueAsType();
ptr_type ptr = memory.add_cells(layout_resolver.get_type_layout<BlueprintFieldType>(pointee));
frame.scalars[current_arg] = put_into_assignment(ptr, is_private);
frame.scalars[current_arg] = pointer_into_assignment(ptr);
ret_gap += 1;
continue;
}
Expand Down Expand Up @@ -448,7 +454,7 @@ namespace nil {
return true;
}
size_t get_idx() const {
return public_input_idx;
return constant_idx;
}

const std::string &get_error() const {
Expand All @@ -462,6 +468,7 @@ namespace nil {
LayoutResolver &layout_resolver;
size_t public_input_idx;
size_t private_input_idx;
size_t constant_idx;
std::string error;
};
} // namespace blueprint
Expand Down
15 changes: 7 additions & 8 deletions include/nil/blueprint/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace nil {
const auto start_row = assignments[currProverIdx].allocated_rows();
const auto v = handle_comparison_component<BlueprintFieldType, ArithmetizationParams>(
p, lhs, rhs, bitness,
circuits[currProverIdx], assignments[currProverIdx], start_row, public_input_idx);
circuits[currProverIdx], assignments[currProverIdx], start_row);
if (next_prover) {
variables[inst] = save_shared_var(assignments[currProverIdx], v);
} else {
Expand Down Expand Up @@ -192,7 +192,7 @@ namespace nil {
const auto start_row = assignments[currProverIdx].allocated_rows();
auto v = handle_comparison_component<BlueprintFieldType, ArithmetizationParams>(
inst->getPredicate(), lhs[i], rhs[i], bitness,
circuits[currProverIdx], assignments[currProverIdx], start_row, public_input_idx);
circuits[currProverIdx], assignments[currProverIdx], start_row);

res.emplace_back(v);
}
Expand All @@ -218,7 +218,7 @@ namespace nil {
for (size_t i = 0; i < lhs.size(); ++i) {
auto v = handle_comparison_component<BlueprintFieldType, ArithmetizationParams>(
inst->getPredicate(), lhs[i], rhs[i], 0,
circuits[currProverIdx], assignments[currProverIdx], assignments[currProverIdx].allocated_rows(), public_input_idx);
circuits[currProverIdx], assignments[currProverIdx], assignments[currProverIdx].allocated_rows());
res.emplace_back(v);
}

Expand All @@ -227,7 +227,7 @@ namespace nil {
for (size_t i = 1; i < lhs.size(); ++i) {
are_curves_equal = handle_logic_and<BlueprintFieldType, ArithmetizationParams>(
are_curves_equal, res[i], circuits[currProverIdx], assignments[currProverIdx],
assignments[currProverIdx].allocated_rows(), public_input_idx);
assignments[currProverIdx].allocated_rows());
}
if (next_prover) {
frame.scalars[inst] = save_shared_var(assignments[currProverIdx], are_curves_equal);
Expand Down Expand Up @@ -468,7 +468,7 @@ namespace nil {

var comparison_result = handle_comparison_component<BlueprintFieldType, ArithmetizationParams>(
llvm::CmpInst::ICMP_EQ, logical_statement, zero_var, bitness,
circuits[currProverIdx], assignments[currProverIdx], assignments[currProverIdx].allocated_rows(), public_input_idx);
circuits[currProverIdx], assignments[currProverIdx], assignments[currProverIdx].allocated_rows());

circuits[currProverIdx].add_copy_constraint({comparison_result, zero_var});

Expand Down Expand Up @@ -1327,8 +1327,8 @@ namespace nil {
std::cout << std::endl;
return false;
}
public_input_idx = input_reader.get_idx();
call_stack.emplace(std::move(base_frame));
constant_idx = input_reader.get_idx();

for (const llvm::GlobalVariable &global : module.getGlobalList()) {

Expand Down Expand Up @@ -1394,7 +1394,7 @@ namespace nil {
}

template<typename InputType>
var put_into_assignment(InputType input, bool next_prover) {
var put_into_assignment(InputType input, bool next_prover) { // TODO: column index is hardcoded but shouldn't be in the future
if (next_prover && maxNumProvers > 1) {
const auto shared_idx = assignments[currProverIdx].shared_column_size(0);
assignments[currProverIdx].shared(0, shared_idx) = input;
Expand All @@ -1413,7 +1413,6 @@ namespace nil {
std::unordered_map<const llvm::Value *, var> globals;
std::unordered_map<const llvm::BasicBlock *, var> labels;
bool finished = false;
size_t public_input_idx = 0;
size_t constant_idx = 0;
std::unique_ptr<LayoutResolver> layout_resolver;
var undef_var;
Expand Down

0 comments on commit 9cd288e

Please sign in to comment.