1
+ // ---------------------------------------------------------------------------//
2
+ // Copyright (c) 2021 Mikhail Komarov <[email protected] >
3
+ // Copyright (c) 2021 Nikita Kaskov <[email protected] >
4
+ // Copyright (c) 2022 Ilia Shirobokov <[email protected] >
5
+ // Copyright (c) 2022 Alisa Cherniaeva <[email protected] >
6
+ // Copyright (c) 2023 Elena Tatuzova <[email protected] >
7
+ //
8
+ // MIT License
9
+ //
10
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ // of this software and associated documentation files (the "Software"), to deal
12
+ // in the Software without restriction, including without limitation the rights
13
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ // copies of the Software, and to permit persons to whom the Software is
15
+ // furnished to do so, subject to the following conditions:
16
+ //
17
+ // The above copyright notice and this permission notice shall be included in all
18
+ // copies or substantial portions of the Software.
19
+ //
20
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ // SOFTWARE.
27
+ // ---------------------------------------------------------------------------//
28
+
29
+ #ifndef CRYPTO3_ZK_PLONK_PLACEHOLDER_PUBLIC_INPUT_HPP
30
+ #define CRYPTO3_ZK_PLONK_PLACEHOLDER_PUBLIC_INPUT_HPP
31
+
32
+ #include < nil/crypto3/math/polynomial/polynomial.hpp>
33
+ #include < nil/crypto3/math/polynomial/shift.hpp>
34
+ #include < nil/crypto3/math/domains/evaluation_domain.hpp>
35
+ #include < nil/crypto3/math/algorithms/make_evaluation_domain.hpp>
36
+
37
+ #include < nil/crypto3/hash/sha2.hpp>
38
+
39
+ #include < nil/crypto3/container/merkle/tree.hpp>
40
+
41
+ #include < nil/crypto3/zk/transcript/fiat_shamir.hpp>
42
+ #include < nil/crypto3/zk/snark/arithmetization/plonk/lookup_constraint.hpp>
43
+ #include < nil/crypto3/zk/snark/systems/plonk/placeholder/params.hpp>
44
+ #include < nil/crypto3/zk/snark/systems/plonk/placeholder/detail/placeholder_policy.hpp>
45
+ #include < nil/crypto3/zk/snark/systems/plonk/placeholder/preprocessor.hpp>
46
+
47
+ namespace nil {
48
+ namespace crypto3 {
49
+ namespace zk {
50
+ namespace snark {
51
+ template <typename PlaceholderParams>
52
+ struct public_input_processor {
53
+ using field_type = typename PlaceholderParams::field_type;
54
+ using public_input_gate_type = typename PlaceholderParams::constraint_system_type::public_input_gate_type;
55
+ using common_data_type = const typename placeholder_public_preprocessor<field_type, PlaceholderParams>::preprocessed_data_type::common_data_type;
56
+ using policy_type = detail::placeholder_policy<field_type, PlaceholderParams>;
57
+ using assignment_type = plonk_polynomial_dfs_table<field_type, typename PlaceholderParams::arithmetization_params>;
58
+ using transcript_type = typename transcript::fiat_shamir_heuristic_sequential<typename PlaceholderParams::transcript_hash_type>;
59
+ using variable_type = plonk_variable<typename field_type::value_type>;
60
+ using proof_type = placeholder_proof<field_type, PlaceholderParams>;
61
+
62
+ static inline math::polynomial_dfs<typename field_type::value_type> prove (
63
+ const public_input_gate_type &public_input_gate,
64
+ const common_data_type &common_data,
65
+ const assignment_type &assignments,
66
+ transcript_type &transcript
67
+ ){
68
+ math::polynomial_dfs<typename field_type::value_type> result;
69
+ if (public_input_gate.size () == 0 ){
70
+ return result;
71
+ }
72
+ auto alpha = transcript.template challenge <field_type>();
73
+ for (std::size_t i = 0 ; i < public_input_gate.size (); i++){
74
+ const auto &var = public_input_gate[i];
75
+ math::polynomial_dfs<typename field_type::value_type> l;
76
+
77
+ if (var.type == variable_type::witness){
78
+ l = assignments.witness (var.index );
79
+ } else if (var.type == variable_type::public_input){
80
+ l = assignments.public_input (var.index );
81
+ } else if (var.type == variable_type::constant){
82
+ l = assignments.constant (var.index );
83
+ } else if (var.type == variable_type::selector){
84
+ l = assignments.selector (var.index );
85
+ } else {
86
+ }
87
+ l -= typename field_type::value_type (l[0 ]);
88
+ l *= math::polynomial_shift (common_data.lagrange_0 , var.rotation , common_data.basic_domain ->m );
89
+ result *= alpha;
90
+ result += l;
91
+ }
92
+ return result;
93
+ }
94
+
95
+ static inline typename field_type::value_type verify (
96
+ const std::vector<typename field_type::value_type> &public_input,
97
+ typename policy_type::evaluation_map &columns_at_y,
98
+ typename field_type::value_type challenge,
99
+ const public_input_gate_type &public_input_gate,
100
+ const common_data_type &common_data,
101
+ transcript_type &transcript
102
+ ){
103
+ if (public_input_gate.size () == 0 ){
104
+ return field_type::value_type::zero ();
105
+ }
106
+ BOOST_ASSERT (public_input_gate.size () == public_input.size ());
107
+
108
+ typename field_type::value_type result;
109
+ auto alpha = transcript.template challenge <field_type>();
110
+
111
+ for (std::size_t i = 0 ; i < public_input_gate.size (); i++){
112
+ const auto &var = public_input_gate[i];
113
+ auto key = std::tuple (var.index , var.rotation , var.type );
114
+ auto value = columns_at_y[key] - public_input[i];
115
+ value *= math::polynomial_shift (common_data.lagrange_0 , var.rotation , common_data.basic_domain ->m ).evaluate (challenge);
116
+ result *= alpha;
117
+ result += value;
118
+ }
119
+ return result;
120
+ }
121
+ };
122
+ } // namespace snark
123
+ } // namespace zk
124
+ } // namespace crypto3
125
+ } // namespace nil
126
+
127
+ #endif // #ifndef CRYPTO3_ZK_PLONK_PLACEHOLDER_PUBLIC_INPUT_ARGUMENT_HPP
0 commit comments