r1cs_pcd_params.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2021 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2020-2021 Nikita Kaskov <nbering@nil.foundation>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_ZK_R1CS_PCD_PARAMS_HPP
27 #define CRYPTO3_ZK_R1CS_PCD_PARAMS_HPP
28 
29 #include <memory>
30 #include <vector>
31 
32 #include <nil/crypto3/zk/snark/schemes/pcd/r1cs_pcd/compliance_predicate/cp_handler.hpp>
33 
34 namespace nil {
35  namespace crypto3 {
36  namespace zk {
37  namespace snark {
38 
39  template<typename FieldType>
41  public:
42  std::shared_ptr<r1cs_pcd_message<FieldType>> outgoing_message;
43 
45  const std::shared_ptr<r1cs_pcd_message<FieldType>> &outgoing_message) :
47  }
49  return outgoing_message->as_r1cs_variable_assignment();
50  }
51  };
52 
53  template<typename FieldType>
55  public:
56  std::vector<std::shared_ptr<r1cs_pcd_message<FieldType>>> incoming_messages;
57  std::shared_ptr<r1cs_pcd_local_data<FieldType>> local_data;
59 
62  const std::shared_ptr<r1cs_pcd_local_data<FieldType>> &local_data,
66  }
67 
69  const std::vector<std::size_t> &incoming_message_payload_lengths) const {
70 
71  const std::size_t arity = incoming_messages.size();
72 
74  result.emplace_back(typename FieldType::value_type(arity));
75 
76  const std::size_t max_arity = incoming_message_payload_lengths.size();
77  assert(arity <= max_arity);
78 
79  for (std::size_t i = 0; i < arity; ++i) {
80  const r1cs_variable_assignment<FieldType> msg_as_r1cs_va =
81  incoming_messages[i]->as_r1cs_variable_assignment();
82  assert(msg_as_r1cs_va.size() == (1 + incoming_message_payload_lengths[i]));
83  result.insert(result.end(), msg_as_r1cs_va.begin(), msg_as_r1cs_va.end());
84  }
85 
86  /* pad with dummy messages of appropriate size */
87  for (std::size_t i = arity; i < max_arity; ++i) {
88  result.resize(result.size() + (1 + incoming_message_payload_lengths[i]),
89  FieldType::value_type::zero());
90  }
91 
92  const r1cs_variable_assignment<FieldType> local_data_as_r1cs_va =
93  local_data->as_r1cs_variable_assignment();
94  result.insert(result.end(), local_data_as_r1cs_va.begin(), local_data_as_r1cs_va.end());
95  result.insert(result.end(), witness.begin(), witness.end());
96 
97  return result;
98  }
99  };
100  } // namespace snark
101  } // namespace zk
102  } // namespace crypto3
103 } // namespace nil
104 
105 #endif // R1CS_PCD_PARAMS_HPP
r1cs_pcd_witness< FieldType > witness
Definition: r1cs_pcd_params.hpp:58
r1cs_pcd_compliance_predicate_auxiliary_input(const std::vector< std::shared_ptr< r1cs_pcd_message< FieldType >>> &incoming_messages, const std::shared_ptr< r1cs_pcd_local_data< FieldType >> &local_data, const r1cs_pcd_witness< FieldType > &witness)
Definition: r1cs_pcd_params.hpp:60
r1cs_auxiliary_input< FieldType > as_r1cs_auxiliary_input(const std::vector< std::size_t > &incoming_message_payload_lengths) const
Definition: r1cs_pcd_params.hpp:68
std::shared_ptr< r1cs_pcd_local_data< FieldType > > local_data
Definition: r1cs_pcd_params.hpp:57
std::vector< std::shared_ptr< r1cs_pcd_message< FieldType > > > incoming_messages
Definition: r1cs_pcd_params.hpp:56
r1cs_pcd_compliance_predicate_primary_input(const std::shared_ptr< r1cs_pcd_message< FieldType >> &outgoing_message)
Definition: r1cs_pcd_params.hpp:44
std::shared_ptr< r1cs_pcd_message< FieldType > > outgoing_message
Definition: r1cs_pcd_params.hpp:42
r1cs_primary_input< FieldType > as_r1cs_primary_input() const
Definition: r1cs_pcd_params.hpp:48
vector(T, U...) -> vector< std::enable_if_t<(std::is_same_v< T, U > &&...), T >, 1+sizeof...(U)>
deduction guide for uniform initialization
std::vector< typename FieldType::value_type > r1cs_auxiliary_input
Definition: r1cs.hpp:104
std::vector< typename FieldType::value_type > r1cs_pcd_witness
Definition: compliance_predicate.hpp:86
std::vector< typename FieldType::value_type > r1cs_primary_input
Definition: r1cs.hpp:101
std::vector< typename FieldType::value_type > r1cs_variable_assignment
Definition: r1cs.hpp:107
Definition: pair.hpp:31
Definition: compliance_predicate.hpp:77
Definition: compliance_predicate.hpp:56