5
5
6
6
namespace {
7
7
auto & engine = numeric::random::get_debug_engine();
8
- }
8
+ } // namespace
9
9
10
10
using namespace barretenberg ;
11
11
using namespace proof_system ::plonk;
12
12
13
13
namespace proof_system ::plonk::test_verification_key {
14
14
15
15
/* *
16
- * @brief generated a random vk data for use in tests
16
+ * @brief generate a random vk data for use in tests
17
17
*
18
18
* @return verification_key_data randomly generated
19
19
*/
20
- verification_key_data rand_vk_data ()
21
- {
22
- verification_key_data key_data;
23
- key_data.composer_type = static_cast <uint32_t >(proof_system::ComposerType::STANDARD);
24
- key_data.circuit_size = 1024 ; // not random - must be power of 2
25
- key_data.num_public_inputs = engine.get_random_uint32 ();
26
- key_data.commitments [" test1" ] = g1::element::random_element ();
27
- key_data.commitments [" test2" ] = g1::element::random_element ();
28
- key_data.commitments [" foo1" ] = g1::element::random_element ();
29
- key_data.commitments [" foo2" ] = g1::element::random_element ();
30
- return key_data;
20
+ verification_key_data rand_vk_data () {
21
+ verification_key_data vk_data;
22
+ vk_data.composer_type = static_cast <uint32_t >(proof_system::ComposerType::STANDARD);
23
+ vk_data.circuit_size = 1024 ; // not random - must be power of 2
24
+ vk_data.num_public_inputs = engine.get_random_uint32 ();
25
+ vk_data.commitments [" test1" ] = g1::element::random_element ();
26
+ vk_data.commitments [" test2" ] = g1::element::random_element ();
27
+ vk_data.commitments [" foo1" ] = g1::element::random_element ();
28
+ vk_data.commitments [" foo2" ] = g1::element::random_element ();
29
+ return vk_data;
31
30
}
32
31
33
32
/* *
34
33
* @brief expect that two vk data compressions are equal for a few different hash indices
35
34
*
36
- * @param key0_data
37
- * @param key1_data
35
+ * @param vk0_data
36
+ * @param vk1_data
38
37
*/
39
- void expect_compressions_eq (verification_key_data key0_data , verification_key_data key1_data )
38
+ void expect_compressions_eq (verification_key_data vk0_data , verification_key_data vk1_data )
40
39
{
41
40
// 0 hash index
42
- EXPECT_EQ (key0_data .compress_native (0 ), key1_data .compress_native (0 ));
41
+ EXPECT_EQ (vk0_data .compress_native (0 ), vk1_data .compress_native (0 ));
43
42
// nonzero hash index
44
- EXPECT_EQ (key0_data .compress_native (15 ), key1_data .compress_native (15 ));
43
+ EXPECT_EQ (vk0_data .compress_native (15 ), vk1_data .compress_native (15 ));
45
44
}
46
45
47
46
/* *
48
47
* @brief expect that two vk data compressions are not-equal for a few different hash indices
49
48
*
50
- * @param key0_data
51
- * @param key1_data
49
+ * @param vk0_data
50
+ * @param vk1_data
52
51
*/
53
- void expect_compressions_ne (verification_key_data key0_data , verification_key_data key1_data )
52
+ void expect_compressions_ne (verification_key_data vk0_data , verification_key_data vk1_data )
54
53
{
55
- EXPECT_NE (key0_data .compress_native (0 ), key1_data .compress_native (0 ));
56
- EXPECT_NE (key0_data .compress_native (15 ), key1_data .compress_native (15 ));
57
- // ne hash indeces still lead to ne compressions
58
- EXPECT_NE (key0_data .compress_native (0 ), key1_data .compress_native (15 ));
59
- EXPECT_NE (key0_data .compress_native (14 ), key1_data .compress_native (15 ));
54
+ EXPECT_NE (vk0_data .compress_native (0 ), vk1_data .compress_native (0 ));
55
+ EXPECT_NE (vk0_data .compress_native (15 ), vk1_data .compress_native (15 ));
56
+ // ne hash indices still lead to ne compressions
57
+ EXPECT_NE (vk0_data .compress_native (0 ), vk1_data .compress_native (15 ));
58
+ EXPECT_NE (vk0_data .compress_native (14 ), vk1_data .compress_native (15 ));
60
59
}
61
60
62
61
TEST (verification_key, buffer_serialization)
63
62
{
64
- verification_key_data key_data = rand_vk_data ();
63
+ verification_key_data vk_data = rand_vk_data ();
65
64
66
- auto buf = to_buffer (key_data );
65
+ auto buf = to_buffer (vk_data );
67
66
auto result = from_buffer<verification_key_data>(buf);
68
67
69
- EXPECT_EQ (key_data , result);
68
+ EXPECT_EQ (vk_data , result);
70
69
}
71
70
72
71
TEST (verification_key, stream_serialization)
73
72
{
74
- verification_key_data key_data = rand_vk_data ();
73
+ verification_key_data vk_data = rand_vk_data ();
75
74
76
75
std::stringstream s;
77
- write (s, key_data );
76
+ write (s, vk_data );
78
77
79
78
verification_key_data result;
80
79
read (static_cast <std::istream&>(s), result);
81
80
82
- EXPECT_EQ (key_data , result);
81
+ EXPECT_EQ (vk_data , result);
83
82
}
84
83
85
84
TEST (verification_key, basic_compression_equality)
86
85
{
87
- verification_key_data key0_data = rand_vk_data ();
88
- verification_key_data key1_data = key0_data ; // copy
89
- expect_compressions_eq (key0_data, key1_data );
86
+ verification_key_data vk0_data = rand_vk_data ();
87
+ verification_key_data vk1_data = vk0_data ; // copy
88
+ expect_compressions_eq (vk0_data, vk1_data );
90
89
}
91
90
92
91
TEST (verification_key, compression_inequality_index_mismatch)
93
92
{
94
- verification_key_data key0_data = rand_vk_data ();
95
- verification_key_data key1_data = key0_data ; // copy
93
+ verification_key_data vk0_data = rand_vk_data ();
94
+ verification_key_data vk1_data = vk0_data ; // copy
96
95
// inquality on hash index mismatch
97
- EXPECT_NE (key0_data .compress_native (0 ), key1_data .compress_native (15 ));
98
- EXPECT_NE (key0_data .compress_native (14 ), key1_data .compress_native (15 ));
96
+ EXPECT_NE (vk0_data .compress_native (0 ), vk1_data .compress_native (15 ));
97
+ EXPECT_NE (vk0_data .compress_native (14 ), vk1_data .compress_native (15 ));
99
98
}
100
99
101
100
TEST (verification_key, compression_inequality_composer_type)
102
101
{
103
- verification_key_data key0_data = rand_vk_data ();
104
- verification_key_data key1_data = key0_data ; // copy
105
- key0_data .composer_type = static_cast <uint32_t >(proof_system::ComposerType::PLOOKUP);
106
- expect_compressions_ne (key0_data, key1_data );
102
+ verification_key_data vk0_data = rand_vk_data ();
103
+ verification_key_data vk1_data = vk0_data ; // copy
104
+ vk0_data .composer_type = static_cast <uint32_t >(proof_system::ComposerType::PLOOKUP);
105
+ expect_compressions_ne (vk0_data, vk1_data );
107
106
}
108
107
109
- TEST (verification_key, compression_inequality_different_circuit_size)
108
+ TEST (verification_key, compression_inequality_different_circuit_size) \
110
109
{
111
- verification_key_data key0_data = rand_vk_data ();
112
- verification_key_data key1_data = key0_data ;
113
- key0_data .circuit_size = 4096 ;
114
- expect_compressions_ne (key0_data, key1_data );
110
+ verification_key_data vk0_data = rand_vk_data ();
111
+ verification_key_data vk1_data = vk0_data ;
112
+ vk0_data .circuit_size = 4096 ;
113
+ expect_compressions_ne (vk0_data, vk1_data );
115
114
}
116
115
117
- TEST (verification_key, compression_inequality_different_num_public_inputs)
116
+ TEST (verification_key, compression_inequality_different_num_public_inputs) \
118
117
{
119
- verification_key_data key0_data = rand_vk_data ();
120
- verification_key_data key1_data = key0_data ;
121
- key0_data .num_public_inputs = 42 ;
122
- expect_compressions_ne (key0_data, key1_data );
118
+ verification_key_data vk0_data = rand_vk_data ();
119
+ verification_key_data vk1_data = vk0_data ;
120
+ vk0_data .num_public_inputs = 42 ;
121
+ expect_compressions_ne (vk0_data, vk1_data );
123
122
}
124
123
125
- TEST (verification_key, compression_inequality_different_commitments)
124
+ TEST (verification_key, compression_inequality_different_commitments) \
126
125
{
127
- verification_key_data key0_data = rand_vk_data ();
128
- verification_key_data key1_data = key0_data ;
129
- key0_data .commitments [" test1" ] = g1::element::random_element ();
130
- expect_compressions_ne (key0_data, key1_data );
126
+ verification_key_data vk0_data = rand_vk_data ();
127
+ verification_key_data vk1_data = vk0_data ;
128
+ vk0_data .commitments [" test1" ] = g1::element::random_element ();
129
+ expect_compressions_ne (vk0_data, vk1_data );
131
130
}
132
131
133
- TEST (verification_key, compression_inequality_different_num_commitments)
132
+ TEST (verification_key, compression_inequality_different_num_commitments) \
134
133
{
135
- verification_key_data key0_data = rand_vk_data ();
136
- verification_key_data key1_data = key0_data ;
137
- key0_data .commitments [" new" ] = g1::element::random_element ();
138
- expect_compressions_ne (key0_data, key1_data );
134
+ verification_key_data vk0_data = rand_vk_data ();
135
+ verification_key_data vk1_data = vk0_data ;
136
+ vk0_data .commitments [" new" ] = g1::element::random_element ();
137
+ expect_compressions_ne (vk0_data, vk1_data );
139
138
}
140
139
141
- TEST (verification_key, compression_equality_different_contains_recursive_proof)
140
+ TEST (verification_key, compression_equality_different_contains_recursive_proof) \
142
141
{
143
- verification_key_data key0_data = rand_vk_data ();
144
- verification_key_data key1_data = key0_data ;
145
- key0_data .contains_recursive_proof = false ;
146
- key1_data .contains_recursive_proof = true ;
147
- expect_compressions_eq (key0_data, key1_data );
142
+ verification_key_data vk0_data = rand_vk_data ();
143
+ verification_key_data vk1_data = vk0_data ;
144
+ vk0_data .contains_recursive_proof = false ;
145
+ vk1_data .contains_recursive_proof = true ;
146
+ expect_compressions_eq (vk0_data, vk1_data );
148
147
}
149
148
150
- TEST (verification_key, compression_equality_different_recursive_proof_public_input_indices)
149
+ TEST (verification_key, compression_equality_different_recursive_proof_public_input_indices) \
151
150
{
152
- verification_key_data key0_data = rand_vk_data ();
153
- verification_key_data key1_data = key0_data ;
154
- key1_data .recursive_proof_public_input_indices .push_back (42 );
155
- expect_compressions_eq (key0_data, key1_data );
151
+ verification_key_data vk0_data = rand_vk_data ();
152
+ verification_key_data vk1_data = vk0_data ;
153
+ vk1_data .recursive_proof_public_input_indices .push_back (42 );
154
+ expect_compressions_eq (vk0_data, vk1_data );
156
155
}
157
156
} // namespace proof_system::plonk::test_verification_key
0 commit comments