Skip to content

Commit

Permalink
Enable multi prover
Browse files Browse the repository at this point in the history
  • Loading branch information
akokoshn authored and nkaskov committed Nov 6, 2023
1 parent 7dd5753 commit cf7d8a6
Show file tree
Hide file tree
Showing 23 changed files with 414 additions and 209 deletions.
4 changes: 2 additions & 2 deletions include/nil/blueprint/bitwise/and.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace nil {
handle_bitwise_and_component(
const typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &x,
const typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &y,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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) {
Expand Down
4 changes: 2 additions & 2 deletions include/nil/blueprint/bitwise/or.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace nil {
handle_bitwise_or_component(
const typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &x,
const typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &y,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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) {
Expand Down
4 changes: 2 additions & 2 deletions include/nil/blueprint/bitwise/xor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ namespace nil {
handle_bitwise_xor_component(
const typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &x,
const typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &y,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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) {
Expand Down
4 changes: 2 additions & 2 deletions include/nil/blueprint/boolean/logic_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ namespace nil {
handle_logic_and(
const typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &x,
const typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &y,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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) {
Expand Down
4 changes: 2 additions & 2 deletions include/nil/blueprint/comparison/comparison.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace nil {
const typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &x,
const typename crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type> &y,
std::size_t Bitness,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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) {
Expand Down
25 changes: 17 additions & 8 deletions include/nil/blueprint/curves/addition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ namespace nil {
handle_native_curve_unified_addition_component(
llvm::Value *operand0, llvm::Value *operand1,
typename std::map<const llvm::Value *, std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>>> &vectors,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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) {

Expand Down Expand Up @@ -94,8 +94,8 @@ namespace nil {
handle_non_native_curve_addition_component(
llvm::Value *operand0, llvm::Value *operand1,
typename std::map<const llvm::Value *, std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>>> &vectors,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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) {

Expand Down Expand Up @@ -150,10 +150,10 @@ namespace nil {
void handle_curve_addition_component(
const llvm::Instruction *inst,
stack_frame<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &frame,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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::uint32_t start_row, bool next_prover) {

using non_native_policy_type = basic_non_native_policy<BlueprintFieldType>;

Expand All @@ -178,7 +178,11 @@ namespace nil {
detail::handle_native_curve_unified_addition_component<BlueprintFieldType, ArithmetizationParams, operating_curve_type>(
operand0, operand1, frame.vectors, bp, assignment, start_row);
std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> res_vector = {res.X, res.Y};
frame.vectors[inst] = res_vector;
if (next_prover) {
frame.vectors[inst] = save_shared_var(assignment, res_vector);
} else {
frame.vectors[inst] = res_vector;
}
} else {
UNREACHABLE("non-native pallas is undefined");
}
Expand Down Expand Up @@ -226,6 +230,11 @@ namespace nil {
res.output.y[2],
res.output.y[3]};
frame.vectors[inst] = res_vector;
if (next_prover) {
frame.vectors[inst] = save_shared_var(assignment, res_vector);
} else {
frame.vectors[inst] = res_vector;
}
}

break;
Expand Down
30 changes: 20 additions & 10 deletions include/nil/blueprint/curves/multiplication.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ namespace nil {
handle_native_curve_non_native_scalar_multiplication_component(
llvm::Value *operand_curve, llvm::Value *operand_field,
typename std::map<const llvm::Value *, std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>>> &vectors,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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) {

Expand Down Expand Up @@ -96,8 +96,8 @@ namespace nil {
llvm::Value *operand_field,
typename std::map<const llvm::Value *, std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>>> &vectors,
typename std::map<const llvm::Value *, crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &variables,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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) {

Expand Down Expand Up @@ -141,10 +141,10 @@ namespace nil {
void handle_curve_multiplication_component(
const llvm::Instruction *inst,
stack_frame<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &frame,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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::uint32_t start_row, bool next_prover) {

using non_native_policy_type = basic_non_native_policy<BlueprintFieldType>;

Expand Down Expand Up @@ -194,7 +194,12 @@ namespace nil {
detail::handle_native_curve_non_native_scalar_multiplication_component<BlueprintFieldType, ArithmetizationParams, operating_curve_type>(
operand_curve, operand_field, frame.vectors, bp, assignment, start_row);
std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> res_vector = {res.X, res.Y};
frame.vectors[inst] = res_vector;
if (next_prover) {
std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> res_vector;
frame.vectors[inst] = save_shared_var(assignment, res_vector);
} else {
frame.vectors[inst] = res_vector;
}
} else {
UNREACHABLE("non-native pallas multiplication is not implemented");
}
Expand Down Expand Up @@ -241,8 +246,13 @@ namespace nil {
res.output.y[3]
};

frame.vectors[inst] = std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>>(
std::begin(res_vector), std::end(res_vector));
if (next_prover) {
frame.vectors[inst] = save_shared_var(assignment, std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>>(
std::begin(res_vector), std::end(res_vector)));
} else {
frame.vectors[inst] = std::vector<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>>(
std::begin(res_vector), std::end(res_vector));
}
}

break;
Expand Down
6 changes: 3 additions & 3 deletions include/nil/blueprint/curves/subtraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ namespace nil {
void handle_curve_subtraction_component(
const llvm::Instruction *inst,
stack_frame<crypto3::zk::snark::plonk_variable<typename BlueprintFieldType::value_type>> &frame,
circuit<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>> &bp,
assignment<crypto3::zk::snark::plonk_constraint_system<BlueprintFieldType, ArithmetizationParams>>
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::uint32_t start_row, bool next_prover) {

using non_native_policy_type = basic_non_native_policy<BlueprintFieldType>;

Expand Down
Loading

0 comments on commit cf7d8a6

Please sign in to comment.